<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260319142344 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create homework_rule_exceptions table for story 5.6';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE homework_rule_exceptions (
            id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
            tenant_id UUID NOT NULL,
            homework_id UUID NOT NULL REFERENCES homework(id) ON DELETE CASCADE,
            rule_type VARCHAR(100) NOT NULL,
            justification TEXT NOT NULL,
            created_by UUID NOT NULL REFERENCES users(id),
            created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
        )');

        $this->addSql('CREATE INDEX idx_hw_exceptions_tenant ON homework_rule_exceptions(tenant_id)');
        $this->addSql('CREATE INDEX idx_hw_exceptions_homework ON homework_rule_exceptions(homework_id)');
        $this->addSql('CREATE INDEX idx_hw_exceptions_created_at ON homework_rule_exceptions(created_at)');
        $this->addSql('CREATE INDEX idx_hw_exceptions_created_by ON homework_rule_exceptions(created_by)');
    }

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