<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->decimal('shipping_cost', 10, 2)->default(0)->after('discount_from_points');
            $table->foreignId('shipping_address_id')->nullable()->after('notes')->constrained('user_addresses')->nullOnDelete();
            $table->string('shipping_governorate')->nullable()->after('shipping_address_id');
            $table->text('shipping_address_snapshot')->nullable()->after('shipping_governorate');
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeign(['shipping_address_id']);
            $table->dropColumn(['shipping_cost', 'shipping_address_id', 'shipping_governorate', 'shipping_address_snapshot']);
        });
    }
};
