<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('reservations', function (Blueprint $table) {
            $table->bigIncrements('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');

                $table->unsignedBigInteger('checkin_receptionist_id')->nullable()->default(1);
                $table->foreign('checkin_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('date_entry');
                $table->time('hour_entry', 0)->default('13:00');
                $table->date('date_departure');
                $table->time('hour_departure', 0)->default('12:00');
                $table->integer('number_nights');
                $table->integer('number_hours');
                $table->integer('number_adults');
                $table->integer('number_children');
                $table->boolean('include_children_in_pax')->default(true);
                $table->boolean('requiere_invoice')->default(false);
                $table->uuid('invoice_uuid')->nullable();
                $table->string('reservation_reason')->nullable();
                $table->string('notes')->default('Ninguna');

                // Of Stay
                $table->boolean('is_express')->default(false);

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

                $table->unsignedBigInteger('roomType_id')->nullable()->default(2);
                $table->foreign('roomType_id')
                    ->references('id')->on('room_types')
                    ->onDelete('set null');

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

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

                $table->unsignedBigInteger('source_id')->nullable();
                $table->foreign('source_id')
                    ->references('id')->on('sources')
                    ->onDelete('set null');

                // Of Payment
                $table->decimal('discount_percentage',10,2)->default(0.0);
                $table->decimal('original_suggested_price',10,2)->nullable();
                $table->decimal('suggested_price', 10, 2);
                $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('status_id'); //Estado de la Reservación
                $table->foreign('status_id')
                    ->references('id')->on('statuses')
                    ->onDelete('cascade');

                $table->unsignedBigInteger('guest_status_id')->nullable();
                $table->foreign('guest_status_id')
                    ->references('id')->on('statuses')
                    ->onDelete('cascade');

                $table->enum('has_checkIn', ['Si', 'No'])->default('No');
                $table->enum('has_checkOut', ['Si', 'No'])->default('No');
                $table->string('payment_status');
                $table->boolean('show_in_calendar')->default(1);

            $table->timestamps();

        });
    }

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