<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260827133000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute l index utilise par la purge des inscriptions expirees.';
    }

    public function up(Schema $schema): void
    {
        $this->abortIf(!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Cette migration nécessite PostgreSQL.');

        $this->addSql(<<<'SQL'
            CREATE INDEX IF NOT EXISTS user_expired_registration_purge_idx
            ON user_user (email_verification_expires_at, id)
            WHERE is_verified = FALSE
              AND email_verification_expires_at IS NOT NULL
            SQL);
    }

    public function down(Schema $schema): void
    {
        $this->abortIf(!$this->connection->getDatabasePlatform() instanceof PostgreSQLPlatform, 'Cette migration nécessite PostgreSQL.');

        $this->addSql('DROP INDEX IF EXISTS user_expired_registration_purge_idx');
    }
}
