<?php

/*
 * 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\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20260721120000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute la preuve horodatee des demandes de retractation en ligne.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
            CREATE TABLE cart_withdrawal_request (
                id UUID NOT NULL,
                cart_id UUID NOT NULL,
                firstname VARCHAR(255) NOT NULL,
                lastname VARCHAR(255) NOT NULL,
                contract_reference VARCHAR(255) NOT NULL,
                receipt_email VARCHAR(254) NOT NULL,
                submitted_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
                acknowledged_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                processed_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL,
                ip_address VARCHAR(45) DEFAULT NULL,
                user_agent TEXT DEFAULT NULL,
                locale VARCHAR(10) NOT NULL,
                PRIMARY KEY(id)
            )
            SQL);
        $this->addSql('CREATE UNIQUE INDEX UNIQ_3F2D6EBA1AD5CDBF ON cart_withdrawal_request (cart_id)');
        $this->addSql('ALTER TABLE cart_withdrawal_request ADD CONSTRAINT FK_CART_WITHDRAWAL_REQUEST_CART FOREIGN KEY (cart_id) REFERENCES cart_cart (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql("COMMENT ON COLUMN cart_withdrawal_request.id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN cart_withdrawal_request.cart_id IS '(DC2Type:uuid)'");
        $this->addSql("COMMENT ON COLUMN cart_withdrawal_request.submitted_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN cart_withdrawal_request.acknowledged_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN cart_withdrawal_request.processed_at IS '(DC2Type:datetime_immutable)'");
    }

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