<?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('police_guest_registrations', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('booking_id')->nullable()->constrained()->nullOnDelete();
            $table->foreignId('room_id')->nullable()->constrained()->nullOnDelete();
            $table->date('arrival_date')->index();
            $table->string('room_code', 20)->index();
            $table->unsignedTinyInteger('guest_number')->default(1);
            $table->string('document_type', 100)->nullable();
            $table->string('surname', 120);
            $table->string('name', 120);
            $table->string('nationality', 120)->nullable();
            $table->string('fiscal_code', 50)->nullable();
            $table->date('birth_date')->nullable();
            $table->string('birth_place', 160)->nullable();
            $table->string('gender', 20)->nullable();
            $table->unsignedSmallInteger('height_cm')->nullable();
            $table->string('document_number', 120)->nullable();
            $table->date('document_issue_date')->nullable();
            $table->date('document_expiry_date')->nullable();
            $table->string('document_issuing_municipality', 160)->nullable();
            $table->string('document_photo_1_path')->nullable();
            $table->string('document_photo_2_path')->nullable();
            $table->string('text_file_path')->nullable();
            $table->string('telegram_chat_id', 120)->nullable();
            $table->string('telegram_message_id', 120)->nullable();
            $table->json('raw_payload')->nullable();
            $table->timestamps();

            $table->index(['arrival_date', 'room_code']);
            $table->index(['surname', 'name']);
        });
    }

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