<?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::create('orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('quotation_id')->unique()->constrained()->cascadeOnDelete();
            $table->string('reference_number')->unique();
            $table->enum('status', [
                'pending_payment',
                'payment_received',
                'in_operations',
                'in_shipping',
                'delivered',
                'cancelled',
            ])->default('pending_payment');
            $table->string('payment_reference')->nullable();
            $table->timestamp('payment_received_at')->nullable();
            $table->timestamp('operations_completed_at')->nullable();
            $table->timestamp('shipped_at')->nullable();
            $table->timestamp('delivered_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('orders');
    }
};
