<?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('broadcast_templates', function (Blueprint $table) {
            $table->id();
            $table->text('content')->comment('公告內容'); // e.g., "親愛的 **name**，歡迎光臨！"
            $table->enum('color', ['white', 'red', 'green','blue'])->default('white')->comment('顯示顏色'); 
            $table->boolean('is_active')->default(true); // 啟用狀態
            $table->timestamps();
        });
        Schema::create('text_broadcasts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('template_id')->nullable()->constrained('broadcast_templates')->nullOnDelete();
            $table->text('content'); // Final content with variables replaced
            $table->enum('target_type', ['all', 'rooms'])->default('all');
            $table->timestamps();
        });
        Schema::create('text_broadcast_room', function (Blueprint $table) {
            $table->id();
            $table->foreignId('text_broadcast_id')->constrained()->onDelete('cascade');
            $table->foreignId('room_id')->constrained()->onDelete('cascade');
        });
    }

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