<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260528110000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute la configuration Matomo et le tracking e-commerce.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE shop_shop_config ADD matomo_url VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE shop_shop_config ADD matomo_server_url VARCHAR(255) DEFAULT NULL');
        $this->addSql('ALTER TABLE shop_shop_config ADD matomo_site_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE shop_shop_config ADD enable_matomo_ecommerce_tracking BOOLEAN DEFAULT false NOT NULL');
        $this->addSql('ALTER TABLE cart_cart ADD marketing_attribution JSON DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart_checkout ADD matomo_visitor_id VARCHAR(16) DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart_checkout ADD matomo_user_agent VARCHAR(512) DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart_checkout ADD matomo_url TEXT DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart_checkout ADD matomo_referrer TEXT DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart_checkout ADD marketing_attribution JSON DEFAULT NULL');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE shop_shop_config DROP matomo_url');
        $this->addSql('ALTER TABLE shop_shop_config DROP matomo_server_url');
        $this->addSql('ALTER TABLE shop_shop_config DROP matomo_site_id');
        $this->addSql('ALTER TABLE shop_shop_config DROP enable_matomo_ecommerce_tracking');
        $this->addSql('ALTER TABLE cart_cart DROP marketing_attribution');
        $this->addSql('ALTER TABLE cart_cart_checkout DROP matomo_visitor_id');
        $this->addSql('ALTER TABLE cart_cart_checkout DROP matomo_user_agent');
        $this->addSql('ALTER TABLE cart_cart_checkout DROP matomo_url');
        $this->addSql('ALTER TABLE cart_cart_checkout DROP matomo_referrer');
        $this->addSql('ALTER TABLE cart_cart_checkout DROP marketing_attribution');
    }
}
