<?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('room_amenities', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->string('category', 30); // bathroom|linen|electronics|connectivity|furniture|lighting|climate|kitchenette|amenities_kit|other
            $table->string('amenity_type', 15)->default('fixed'); // fixed|reusable|dedicated|on_demand
            $table->string('icon', 20)->nullable();
            $table->unsignedSmallInteger('default_quantity')->default(1);
            $table->string('status', 15)->default('active');
            $table->timestamps();
        });

        Schema::create('room_inspections', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->unsignedBigInteger('room_id')->index();
            $table->unsignedBigInteger('housekeeping_task_id')->nullable();
            $table->unsignedBigInteger('inspected_by')->nullable();
            $table->timestamp('inspected_at')->nullable();
            $table->string('overall_status', 20)->default('in_progress'); // in_progress|completed
            $table->unsignedSmallInteger('issues_found')->default(0);
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        Schema::create('room_inspection_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->unsignedBigInteger('room_inspection_id')->index();
            $table->unsignedBigInteger('room_amenity_id');
            $table->string('condition', 20)->default('intact'); // intact|needs_fix|needs_maintenance|missing|damaged|replaced
            $table->unsignedSmallInteger('quantity_found')->default(1);
            $table->text('notes')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('room_inspection_items');
        Schema::dropIfExists('room_inspections');
        Schema::dropIfExists('room_amenities');
    }
};
