<?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 Version20260717190000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Aligne le schema des collections de produits avec leur mapping Doctrine.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('UPDATE product_collection SET updated_at = created_at WHERE updated_at IS NULL');
        $this->addSql('ALTER TABLE product_collection ALTER updated_at SET NOT NULL');
        $this->addSql("COMMENT ON COLUMN product_collection.created_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN product_collection.updated_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN product_collection_product.created_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql("COMMENT ON COLUMN product_collection_product.updated_at IS '(DC2Type:datetime_immutable)'");
        $this->addSql('ALTER INDEX IF EXISTS idx_product_collection_automatic_category RENAME TO IDX_6F2A3A195631DB8');
        $this->addSql('ALTER INDEX IF EXISTS idx_product_collection_product_collection RENAME TO IDX_75B0F300514956FD');
        $this->addSql('ALTER INDEX IF EXISTS idx_product_collection_product_product RENAME TO IDX_75B0F3004584665A');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER INDEX IF EXISTS idx_6f2a3a195631db8 RENAME TO IDX_PRODUCT_COLLECTION_AUTOMATIC_CATEGORY');
        $this->addSql('ALTER INDEX IF EXISTS idx_75b0f300514956fd RENAME TO IDX_PRODUCT_COLLECTION_PRODUCT_COLLECTION');
        $this->addSql('ALTER INDEX IF EXISTS idx_75b0f3004584665a RENAME TO IDX_PRODUCT_COLLECTION_PRODUCT_PRODUCT');
        $this->addSql('COMMENT ON COLUMN product_collection.created_at IS NULL');
        $this->addSql('COMMENT ON COLUMN product_collection.updated_at IS NULL');
        $this->addSql('COMMENT ON COLUMN product_collection_product.created_at IS NULL');
        $this->addSql('COMMENT ON COLUMN product_collection_product.updated_at IS NULL');
        $this->addSql('ALTER TABLE product_collection ALTER updated_at DROP NOT NULL');
    }
}
