<?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
    {
        Schema::create('facilities', function (Blueprint $table) {
            $table->id();

            $table->string('name');

            $table->boolean('is_icon')->default(true);
            $table->string('icon_value')->nullable();

            $table->enum('scope', ['room', 'room_category', 'all_rooms'])->default('all_rooms');

            $table->boolean('is_published')->default(true);

            $table->timestamps();
        });

        Schema::create('facility_room', function (Blueprint $table) {
            $table->id();

            $table->foreignId('room_id')->constrained()->cascadeOnDelete();
            $table->foreignId('facility_id')->constrained()->cascadeOnDelete();

            $table->timestamps();
        });

        Schema::create('facility_room_category', function (Blueprint $table) {
            $table->id();

            $table->foreignId('facility_id')->constrained()->cascadeOnDelete();
            $table->foreignId('room_category_id')->constrained()->cascadeOnDelete();

            $table->timestamps();

            $table->unique(['facility_id', 'room_category_id']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('facility_room_category');
        Schema::dropIfExists('facility_room');
        Schema::dropIfExists('facilities');
    }
};
