<?php

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

return new class extends Migration
{
    /**
     * Excepciones al horario base: vacaciones, días festivos, bloqueos puntuales,
     * descansos largos. Si employee_id null → afecta a toda la sede / empresa.
     */
    public function up(): void
    {
        Schema::create('schedule_blocks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->foreignId('branch_id')->nullable()->constrained()->cascadeOnDelete();
            $table->foreignId('employee_id')->nullable()->constrained()->cascadeOnDelete();

            $table->enum('type', ['holiday', 'vacation', 'break', 'sick', 'custom'])->default('custom');
            $table->string('reason')->nullable();
            $table->dateTime('starts_at');
            $table->dateTime('ends_at');
            $table->boolean('is_full_day')->default(false);

            $table->timestamps();

            $table->index(['company_id', 'starts_at', 'ends_at']);
            $table->index(['employee_id', 'starts_at', 'ends_at']);
        });
    }

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