<?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
    {
        $tables = [
            'tax_rates',
            'vendors',
            'service_categories',
            'maintenance_requests',
            'staff_documents'
        ];

        foreach ($tables as $table) {
            if (Schema::hasTable($table) && !Schema::hasColumn($table, 'hotel_id')) {
                Schema::table($table, function (Blueprint $table) {
                    $table->unsignedBigInteger('hotel_id')->nullable()->after('id')->index();
                });
            }
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $tables = [
            'tax_rates',
            'vendors',
            'service_categories',
            'maintenance_requests',
            'staff_documents'
        ];

        foreach ($tables as $tableName) {
            if (Schema::hasTable($tableName) && Schema::hasColumn($tableName, 'hotel_id')) {
                Schema::table($tableName, function (Blueprint $table) {
                    $table->dropColumn('hotel_id');
                });
            }
        }
    }
};
