<?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('class_schedules', function (Blueprint $table) {
            $table->id()->comment('主鍵');

            $table->foreignId('venue_id')
                ->constrained('venues')
                ->cascadeOnDelete()
                ->comment('場館');

            // day_of_week：0=週日、1=週一…6=週六
            $table->unsignedTinyInteger('day_of_week')->comment('星期');
            $table->time('start_time')->comment('開始');
            $table->time('end_time')->comment('結束');

            // coach_id：可對應 coaches.id（外鍵在後續 migration 補上）
            // coach_display_name：無 coach_id 時使用
            $table->string('class_title', 150)->comment('課程');
            $table->unsignedBigInteger('coach_id')->nullable()->comment('教練');
            $table->string('coach_display_name', 100)->nullable()->comment('教練名');

            $table->string('location', 100)->nullable()->comment('地點');
            $table->string('level', 50)->nullable()->comment('程度');
            $table->string('note', 255)->nullable()->comment('備註');

            $table->unsignedInteger('sort_order')->default(0)->comment('排序');
            $table->boolean('is_active')->default(true)->comment('啟用');

            $table->timestamp('created_at')->nullable()->comment('建立');
            $table->timestamp('updated_at')->nullable()->comment('更新');
            $table->timestamp('deleted_at')->nullable()->comment('刪除');

            $table->index(['venue_id', 'day_of_week']);
            $table->index(['day_of_week', 'start_time']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('class_schedules');
    }
};
