<?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 Version20260723250000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute le sujet et le préheader multilingues des relances de panier.';
    }

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

        $this->addSql(<<<'SQL'
            CREATE TABLE marketing_abandoned_cart_config_translation (
                id UUID NOT NULL,
                translatable_id UUID DEFAULT NULL,
                email_subject VARCHAR(150) DEFAULT NULL,
                email_preheader VARCHAR(200) DEFAULT NULL,
                locale VARCHAR(5) NOT NULL,
                PRIMARY KEY(id)
            )
            SQL);
        $this->addSql('CREATE INDEX IDX_451DEB932C2AC5D3 ON marketing_abandoned_cart_config_translation (translatable_id)');
        $this->addSql('CREATE UNIQUE INDEX marketing_abandoned_cart_config_translation_unique_translation ON marketing_abandoned_cart_config_translation (translatable_id, locale)');
        $this->addSql("COMMENT ON COLUMN marketing_abandoned_cart_config_translation.id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN marketing_abandoned_cart_config_translation.translatable_id IS '(DC2Type:uuid)'");
        $this->addSql('ALTER TABLE marketing_abandoned_cart_config_translation ADD CONSTRAINT FK_ABANDONED_CART_CONFIG_TRANSLATION FOREIGN KEY (translatable_id) REFERENCES marketing_abandoned_cart_configuration (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

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

        $this->addSql('DROP TABLE marketing_abandoned_cart_config_translation');
    }
}
