<?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('training_schedules', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('academy_id')->constrained('academies');
            $table->foreignId('training_group_id')->constrained('training_groups');
            $table->unsignedBigInteger('facility_id')->nullable(); // FK added in Phase 5
            $table->integer('day_of_week'); // 0=Sunday, 6=Saturday
            $table->time('start_time');
            $table->time('end_time');
            $table->foreignId('trainer_id')->nullable()->constrained('users');
            $table->foreignId('assistant_trainer_id')->nullable()->constrained('users');
            $table->jsonb('space_reservation_template')->nullable();
            $table->date('effective_from');
            $table->date('effective_until')->nullable();
            $table->boolean('is_active')->default(true);
            $table->text('notes')->nullable();
            $table->timestamps();

            $table->index(['training_group_id', 'is_active']);
            $table->index(['academy_id', 'day_of_week']);
        });
    }

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