<?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('schedule_exceptions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->restrictOnDelete();
            // NULL dentist = clinic-wide closure (public holiday)
            $table->foreignId('dentist_id')->nullable()->constrained()->cascadeOnDelete();
            $table->date('date');
            $table->enum('type', ['off', 'extra']);
            $table->time('start_time')->nullable(); // NULL on 'off' = whole day
            $table->time('end_time')->nullable();
            $table->string('reason', 190)->nullable();
            $table->timestamps();
            $table->index(['tenant_id', 'date']);
        });
    }

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