<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260721133000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute la base des correspondances e-mail vers groupe de prix utilisee lors de l inscription.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE user_imported_client_group (
                id UUID NOT NULL,
                group_id UUID NOT NULL,
                email VARCHAR(60) NOT NULL,
                created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                PRIMARY KEY(id)
            )
            SQL);
        $this->addSql('CREATE UNIQUE INDEX uniq_imported_client_group_email ON user_imported_client_group (email)');
        $this->addSql('CREATE INDEX idx_imported_client_group_group ON user_imported_client_group (group_id)');
        $this->addSql('ALTER TABLE user_imported_client_group ADD CONSTRAINT fk_imported_client_group_group FOREIGN KEY (group_id) REFERENCES product_price_group (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql("COMMENT ON COLUMN user_imported_client_group.id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN user_imported_client_group.group_id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN user_imported_client_group.created_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN user_imported_client_group.updated_at IS '(DC2Type:datetime_immutable)'");
    }

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