<?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('orders', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->constrained()->onDelete('set null');
            $table->string('guest_name')->nullable();
            $table->string('guest_phone')->nullable();
            $table->text('delivery_location');
            $table->enum('delivery_method', ['ena_coach', 'wells_fargo']);
            $table->integer('delivery_fee'); // in KES cents
            $table->integer('subtotal'); // in KES cents
            $table->integer('discount_amount')->default(0); // in KES cents
            $table->integer('total'); // in KES cents
            $table->string('coupon_code')->nullable();
            $table->enum('status', ['pending', 'paid', 'processing', 'shipped', 'delivered', 'cancelled'])->default('pending');
            $table->string('mpesa_transaction_id')->nullable(); // CheckoutRequestID or final MpesaReceiptNumber
            $table->timestamps();
        });
    }

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