<?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('visitors', function (Blueprint $table) {
            $table->id();
            $table->branchColumn();
            $table->string('pass_number', 40);
            $table->string('name');
            $table->string('cnic', 20)->nullable();
            $table->string('phone', 30)->nullable();
            $table->string('purpose')->nullable();
            $table->string('whom_to_meet')->nullable();    // host / person being visited
            $table->unsignedSmallInteger('party_size')->default(1);
            $table->date('visit_date');
            $table->dateTime('check_in')->nullable();
            $table->dateTime('check_out')->nullable();
            $table->enum('status', ['checked_in', 'checked_out'])->default('checked_in')->index();
            $table->string('remarks')->nullable();
            $table->foreignId('recorded_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['branch_id', 'pass_number']);
            $table->index(['branch_id', 'visit_date']);
        });
    }

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