<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260227162304 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create parent_invitations table';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE parent_invitations (
                id UUID PRIMARY KEY,
                tenant_id UUID NOT NULL,
                student_id UUID NOT NULL,
                parent_email VARCHAR(255) NOT NULL,
                code VARCHAR(64) NOT NULL UNIQUE,
                status VARCHAR(20) NOT NULL DEFAULT 'pending',
                expires_at TIMESTAMPTZ NOT NULL,
                created_at TIMESTAMPTZ NOT NULL,
                created_by UUID NOT NULL,
                sent_at TIMESTAMPTZ,
                activated_at TIMESTAMPTZ,
                activated_user_id UUID
            )
        SQL);

        $this->addSql('CREATE INDEX idx_parent_invitations_tenant ON parent_invitations (tenant_id)');
        $this->addSql('CREATE INDEX idx_parent_invitations_code ON parent_invitations (code)');
        $this->addSql('CREATE INDEX idx_parent_invitations_status ON parent_invitations (status)');
        $this->addSql('CREATE INDEX idx_parent_invitations_student ON parent_invitations (student_id)');
        $this->addSql('CREATE INDEX idx_parent_invitations_expires ON parent_invitations (status, expires_at)');
    }

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