<?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->foreignId('user_id')->nullable()->constrained()->cascadeOnDelete()->after('id');
            $table->foreignId('address_id')->nullable()->constrained()->nullOnDelete()->after('user_id');
            $table->string('payment_method')->nullable()->after('status'); // credit_card, debit_card, upi, net_banking, wallet
            $table->string('payment_status')->default('pending')->after('payment_method'); // pending, completed, failed
            $table->string('shipping_status')->default('not_shipped')->after('payment_status');
            $table->text('notes')->nullable()->after('tracking_code');
        });
    }

    public function down(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->dropForeignKeyIfExists('orders_user_id_foreign');
            $table->dropForeignKeyIfExists('orders_address_id_foreign');
            $table->dropColumn(['user_id', 'address_id', 'payment_method', 'payment_status', 'shipping_status', 'notes']);
        });
    }
};
