<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('car_orders', function (Blueprint $table) {
            $table->id();
            $table->string('order_number')->unique();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->foreignId('car_id')->constrained('cars')->onDelete('cascade');
            $table->decimal('amount', 15, 2);               // total order amount
            $table->string('payment_method')->nullable();    // wdmethod name or slug
            $table->string('payment_proof')->nullable();     // uploaded proof file path
            $table->text('payment_details')->nullable();     // any extra payment info
            $table->string('status')->default('pending');    // pending, confirmed, processing, shipped, delivered, cancelled, refunded
            $table->json('tracking_updates')->nullable();    // [{date, status, note}, ...]
            $table->string('tracking_number')->nullable();
            $table->text('shipping_address')->nullable();
            $table->text('admin_note')->nullable();
            $table->text('user_note')->nullable();
            $table->timestamp('paid_at')->nullable();
            $table->timestamp('shipped_at')->nullable();
            $table->timestamp('delivered_at')->nullable();
            $table->timestamps();
        });
    }

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