<?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('day_trip_tour_dates', function (Blueprint $table) {
            $table->id();

            $table->unsignedBigInteger('day_trip_tour_id');
            $table->string('code', 20);

            // Date & Time
            $table->date('tour_date');
            $table->time('departure_time');
            $table->time('return_time');

            // Capacity
            $table->integer('total_capacity');
            $table->integer('remaining_capacity');
            $table->integer('sold_count')->default(0);

            // Pricing Override
            $table->decimal('price_adult', 10, 2)->nullable();
            $table->decimal('price_child', 10, 2)->nullable();
            $table->decimal('price_infant', 10, 2)->nullable();

            // Assignments
            $table->unsignedBigInteger('assigned_vehicle_id')->nullable();
            $table->unsignedBigInteger('assigned_guide_id')->nullable();

            // Status
            $table->enum('status', ['scheduled', 'confirmed', 'in_progress', 'completed', 'cancelled'])->default('scheduled');
            $table->boolean('is_active')->default(true);
            $table->boolean('is_bookable')->default(true);
            $table->boolean('guarantee_departure')->default(false);

            // Notes
            $table->text('notes')->nullable();

            $table->timestamps();

            // Foreign Keys
            $table->foreign('day_trip_tour_id')->references('id')->on('day_trip_tours')->onDelete('cascade');

            // Indexes
            $table->index(['day_trip_tour_id', 'tour_date', 'is_active']);
            $table->index(['tour_date', 'is_bookable']);
        });
    }

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