<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260722220000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Aligne les métadonnées Doctrine de la configuration du contrôle d’âge.';
    }

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

        $this->addSql('ALTER TABLE site_age_verification_config ALTER created_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
        $this->addSql('ALTER TABLE site_age_verification_config ALTER updated_at TYPE TIMESTAMP(0) WITHOUT TIME ZONE');
        $this->addSql("COMMENT ON COLUMN site_age_verification_config.created_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN site_age_verification_config.updated_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql('ALTER INDEX idx_age_verification_country_config RENAME TO IDX_19EA3F5C24DB0683');
    }

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

        $this->addSql('ALTER INDEX idx_19ea3f5c24db0683 RENAME TO idx_age_verification_country_config');
        $this->addSql('COMMENT ON COLUMN site_age_verification_config.created_at IS NULL');
        $this->addSql('COMMENT ON COLUMN site_age_verification_config.updated_at IS NULL');
    }
}
