<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260529123000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute le suivi metier des paniers abandonnes.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE cart_cart ADD last_activity_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE cart_cart ADD abandoned_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('UPDATE cart_cart SET last_activity_at = COALESCE(updated_at, created_at) WHERE last_activity_at IS NULL');
        $this->addSql('CREATE INDEX cart_cart_last_activity_at_idx ON cart_cart (last_activity_at)');
        $this->addSql('CREATE INDEX cart_cart_abandoned_at_idx ON cart_cart (abandoned_at)');
        $this->addSql('COMMENT ON COLUMN cart_cart.last_activity_at IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('COMMENT ON COLUMN cart_cart.abandoned_at IS \'(DC2Type:datetime_immutable)\'');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP INDEX cart_cart_last_activity_at_idx');
        $this->addSql('DROP INDEX cart_cart_abandoned_at_idx');
        $this->addSql('ALTER TABLE cart_cart DROP last_activity_at');
        $this->addSql('ALTER TABLE cart_cart DROP abandoned_at');
    }
}
