<?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::table('police_guest_registrations', function (Blueprint $table): void {
            if (! Schema::hasColumn('police_guest_registrations', 'document_number')) {
                $table->string('document_number', 120)->nullable()->after('height_cm');
            }

            if (! Schema::hasColumn('police_guest_registrations', 'document_issue_date')) {
                $table->date('document_issue_date')->nullable()->after('document_number');
            }

            if (! Schema::hasColumn('police_guest_registrations', 'document_expiry_date')) {
                $table->date('document_expiry_date')->nullable()->after('document_issue_date');
            }

            if (! Schema::hasColumn('police_guest_registrations', 'document_issuing_municipality')) {
                $table->string('document_issuing_municipality', 160)->nullable()->after('document_expiry_date');
            }
        });
    }

    public function down(): void
    {
        Schema::table('police_guest_registrations', function (Blueprint $table): void {
            if (Schema::hasColumn('police_guest_registrations', 'document_issuing_municipality')) {
                $table->dropColumn('document_issuing_municipality');
            }

            if (Schema::hasColumn('police_guest_registrations', 'document_expiry_date')) {
                $table->dropColumn('document_expiry_date');
            }

            if (Schema::hasColumn('police_guest_registrations', 'document_issue_date')) {
                $table->dropColumn('document_issue_date');
            }

            if (Schema::hasColumn('police_guest_registrations', 'document_number')) {
                $table->dropColumn('document_number');
            }
        });
    }
};
