<?php

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

return new class extends Migration {
    public function up(): void
    {
        DB::statement("ALTER TABLE orders MODIFY COLUMN status VARCHAR(50) NOT NULL DEFAULT 'unpaid'");

        Schema::table('orders', function (Blueprint $table) {
            $table->foreignId('shipping_cost_id')->after('status')->nullable()->constrained('shipping_costs')->onDelete('set null');
            $table->string('payment_method')->after('shipping_cost_id')->nullable();
            $table->text('notes')->nullable()->after('payment_method');
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeign(['shipping_cost_id']);
            $table->dropColumn(['shipping_cost_id', 'payment_method', 'notes']);
        });

        DB::statement("ALTER TABLE orders MODIFY COLUMN status ENUM('pending','paid','processing','shipped','delivered','cancelled') NOT NULL DEFAULT 'pending'");
    }
};
