<?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('user_flights', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->timestampTz('departure_date');
            $table->timestampTz('arrival_date');
            $table->string('flight_number')->nullable();
            $table->foreignId('departure_airport_id')->constrained('airports');
            $table->foreignId('arrival_airport_id')->constrained('airports');
            $table->foreignId('airline_id')->nullable()->constrained('airlines');
            $table->foreignId('aircraft_id')->nullable()->constrained('aircraft');
            $table->string('aircraft_registration')->nullable();
            $table->string('seat_number')->nullable();
            $table->unsignedTinyInteger('seat_type_id')->nullable();
            $table->unsignedTinyInteger('flight_reason_id')->nullable();
            $table->unsignedTinyInteger('flight_class_id')->nullable();
            $table->text('note')->nullable();
            $table->timestamps();

            $table->foreign('seat_type_id')->references('id')->on('seat_types');
            $table->foreign('flight_reason_id')->references('id')->on('flight_reasons');
            $table->foreign('flight_class_id')->references('id')->on('flight_classes');
        });
    }

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