<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('availability_rules', function (Blueprint $table) {
            $table->id();

            $table->morphs('available');
            // Creates available_id + available_type for polymorphism

            $table->enum('rule_mode', ['active', 'block']);
            // Active or inactive override

            $table->enum('pattern_type', ['date_range', 'weekly', 'monthly', 'yearly']);

            $table->date('start_date')->nullable();
            $table->date('end_date')->nullable();

            $table->integer('day_of_week')->nullable();   // 0=Sunday … 6=Saturday
            $table->integer('day_of_month')->nullable();  // 1–31
            $table->integer('month_of_year')->nullable(); // 1–12

            $table->string('message')->nullable(); // the message for this

            $table->date('valid_from')->nullable();
            $table->date('valid_until')->nullable();

            $table->timestamps();

            $table->index(['available_id', 'available_type']);
            $table->index(['start_date', 'end_date']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('availability_rules');
    }
};
