<?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('passenger_extra_services', function (Blueprint $table) {
            $table->id();
            $table->string('title');
            $table->string('subtitle')->nullable();
            $table->text('description')->nullable();
            $table->decimal('price_estimate', 12, 2)->nullable();
            $table->unsignedInteger('sort_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        Schema::create('passenger_extra_service_requests', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('passenger_extra_service_id');
            $table->string('status', 32)->default('pending'); // pending, confirmed, completed, cancelled
            $table->text('notes')->nullable();
            $table->text('admin_notes')->nullable();
            $table->decimal('fee_snapshot', 12, 2)->default(0);
            $table->boolean('wheel_milestone_pending')->default(false);
            $table->decimal('wheel_promo_fee_amount', 12, 2)->nullable();
            $table->unsignedTinyInteger('wheel_result')->nullable();
            $table->timestamp('wheel_spun_at')->nullable();
            $table->timestamp('completed_at')->nullable();
            $table->timestamps();

            $table->foreign('user_id', 'fk_pexreq_user')
                ->references('id')->on('users')->cascadeOnDelete();
            $table->foreign('passenger_extra_service_id', 'fk_pexreq_svc')
                ->references('id')->on('passenger_extra_services')->cascadeOnDelete();
        });
    }

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