<?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('academy_schedules', function (Blueprint $table) {
            $table->id();
            $table->foreignId('academy_id')->constrained('academies')->cascadeOnDelete();
            $table->foreignId('court_id')->constrained('courts')->cascadeOnDelete();
            $table->json('days'); 
            $table->time('start_time');
            $table->time('end_time');
            $table->date('start_date');
            $table->date('end_date');
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        Schema::table('academy_schedules', function (Blueprint $table) {
            $table->index(['court_id', 'is_active']);
            $table->index(['court_id', 'start_date', 'end_date']);
            $table->index('academy_id');
        });
    }

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