<?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('trainer_availability', function (Blueprint $table) {
            $table->id();
            $table->foreignId('trainer_id')->constrained('trainers')->cascadeOnDelete();
            $table->string('type', 20);
            $table->smallInteger('day_of_week')->nullable();
            $table->date('specific_date')->nullable();
            $table->time('start_time');
            $table->time('end_time');
            $table->string('reason', 200)->nullable();
            $table->timestamp('created_at')->nullable();

            $table->index('trainer_id');
            $table->index(['trainer_id', 'day_of_week']);
        });

        DB::statement("ALTER TABLE trainer_availability ADD CONSTRAINT trainer_availability_type_check CHECK (type IN ('available', 'unavailable', 'preferred'))");
    }

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