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

              //* Basic Data
                // Of Creation
                $table->date('reservation_date');

                $table->unsignedBigInteger('receptionist_id')->nullable()->default(1);
                $table->foreign('receptionist_id')
                    ->references('id')->on('users')
                    ->onDelete('set null');

                // Of Registration
                $table->unsignedBigInteger('client_id')->nullable();
                $table->foreign('client_id')
                    ->references('id')->on('clients')
                    ->onDelete('set null');

                $table->string('client_reference');
                $table->date('entry_date');
                $table->time('entry_hour', 0)->default('13:00');
                $table->date('departure_date');
                $table->time('departure_hour', 0)->default('12:00');
                $table->integer('number_nights');
                $table->integer('number_adults');
                $table->integer('number_children');
                $table->boolean('requiere_invoice')->default(false);
                $table->string('reservation_reason')->nullable();
                $table->string('notes', 250)->default('Ninguna');

                // Of Stay
                $table->unsignedBigInteger('room_type_id')->nullable();
                $table->foreign('room_type_id')
                    ->references('id')->on('room_types')
                    ->onDelete('set null');

                $table->string('external_type_reference', 64);
                $table->integer('units_quantity');
                $table->json('reserved_rooms');

                // Of Contract
                $table->unsignedBigInteger('ota_connection_id')->nullable();
                $table->foreign('ota_connection_id')
                    ->references('id')->on('ota_connections')
                    ->onDelete('set null');

                // Of Payment
                $table->decimal('final_price', 10, 2);
                $table->decimal('total_price', 10, 2);

                $table->enum('lodging_contract', [
                    'Pago en Destino', 'Cortesia', 'Credito'
                ])->default('Pago en Destino');

                $table->enum('consumption_contract', [
                    'Pago en Destino', 'Cortesia', 'Credito'
                ])->default('Pago en Destino');

                $table->enum('extras_contract', [
                    'Pago en Destino', 'Cortesia', 'Credito'
                ])->default('Pago en Destino');

              //* Control Data
                $table->unsignedBigInteger('global_status_id'); // Estado de la Reservación
                $table->foreign('global_status_id')
                    ->references('id')->on('statuses')
                    ->onDelete('cascade');

                $table->boolean('has_checkIn')->default(0);
                $table->boolean('has_checkOut')->default(0);
                $table->boolean('show_in_calendar')->default(1);
                $table->boolean('is_active')->default(1);
                $table->string('payment_status', 10);

            $table->timestamps();
        });
    }

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