<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('holidays', function (Blueprint $table) {
            $table->id();
            $table->foreignId('academy_id')->constrained('academies');
            $table->foreignId('branch_id')->nullable()->constrained('branches');
            $table->string('name');
            $table->string('name_ar');
            $table->date('date');
            $table->boolean('is_recurring')->default(false);
            $table->string('affects', 20)->default('all');
            $table->timestamps();

            $table->index(['academy_id', 'date']);
        });

        DB::statement("ALTER TABLE holidays ADD CONSTRAINT holidays_affects_check CHECK (affects IN ('all', 'training', 'facility', 'staff'))");
    }

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