<?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('room_status_logs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('branch_id');
            $table->unsignedBigInteger('room_id');
            $table->unsignedBigInteger('user_id'); 
            $table->tinyInteger('is_online')->default(0);
            $table->enum('status', ['active', 'closed','fire', 'error', 'maintain']);
            $table->timestamp('started_at')->nullable();
            $table->timestamp('ended_at')->nullable();
            $table->text('message')->nullable(); // 可填異常原因或操作說明
            $table->enum('source', ['system', 'manual', 'api'])->default('manual');
            $table->index('branch_id');
            $table->index('room_id');
            $table->index('user_id');
            $table->index('started_at');
            $table->timestamps();
        });
    }

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