<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('gas_orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('customer_id')->constrained('users')->onDelete('cascade');
            $table->foreignId('driver_id')->nullable()->constrained('drivers')->onDelete('set null');
            $table->string('order_number')->unique();
            $table->decimal('subtotal', 10, 2);
            $table->decimal('delivery_fee', 8, 2);
            $table->decimal('tax', 8, 2)->default(0.00);
            $table->decimal('total', 10, 2);
            $table->string('delivery_address');
            $table->decimal('delivery_latitude', 10, 8)->nullable();
            $table->decimal('delivery_longitude', 11, 8)->nullable();
            $table->string('status')->default('pending'); // pending, confirmed, preparing, picked_up, delivered, cancelled
            $table->timestamp('preferred_delivery_time')->nullable();
            $table->timestamp('actual_delivery_time')->nullable();
            $table->text('special_instructions')->nullable();
            $table->string('payment_method')->default('cash'); // cash, card, online
            $table->string('payment_status')->default('pending'); // pending, paid, failed
            $table->boolean('is_urgent')->default(false);
            $table->decimal('customer_rating', 3, 2)->nullable();
            $table->text('customer_feedback')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('gas_orders');
    }
};
