<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20260217093243 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create school_calendar_entries table for school calendar management';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE school_calendar_entries (
                id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
                tenant_id UUID NOT NULL,
                academic_year_id UUID NOT NULL,
                entry_type VARCHAR(30) NOT NULL,
                start_date DATE NOT NULL,
                end_date DATE NOT NULL,
                label VARCHAR(100) NOT NULL,
                description TEXT,
                zone VARCHAR(1),
                created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
                CONSTRAINT valid_dates CHECK (end_date >= start_date)
            )
            SQL);

        $this->addSql('CREATE INDEX idx_calendar_tenant ON school_calendar_entries(tenant_id)');
        $this->addSql('CREATE INDEX idx_calendar_year ON school_calendar_entries(academic_year_id)');
        $this->addSql('CREATE INDEX idx_calendar_dates ON school_calendar_entries(start_date, end_date)');
        $this->addSql('CREATE INDEX idx_calendar_type ON school_calendar_entries(entry_type)');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE school_calendar_entries');
    }
}
