<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260427153000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute les dates de publication et les groupes aux blocs d’information boutique';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE shop_information_block ADD published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE shop_information_block ADD un_published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('CREATE TABLE shop_information_block_group_price (information_block_id UUID NOT NULL, product_price_group_id UUID NOT NULL, PRIMARY KEY(information_block_id, product_price_group_id))');
        $this->addSql('CREATE INDEX IDX_3FAE9E2C48F9D6D6 ON shop_information_block_group_price (information_block_id)');
        $this->addSql('CREATE INDEX IDX_3FAE9E2C1DA56B3C ON shop_information_block_group_price (product_price_group_id)');
        $this->addSql('ALTER TABLE shop_information_block_group_price ADD CONSTRAINT FK_3FAE9E2C48F9D6D6 FOREIGN KEY (information_block_id) REFERENCES shop_information_block (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE shop_information_block_group_price ADD CONSTRAINT FK_3FAE9E2C1DA56B3C FOREIGN KEY (product_price_group_id) REFERENCES product_price_group (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE shop_information_block_group_price DROP CONSTRAINT FK_3FAE9E2C48F9D6D6');
        $this->addSql('ALTER TABLE shop_information_block_group_price DROP CONSTRAINT FK_3FAE9E2C1DA56B3C');
        $this->addSql('DROP TABLE shop_information_block_group_price');
        $this->addSql('ALTER TABLE shop_information_block DROP published_at');
        $this->addSql('ALTER TABLE shop_information_block DROP un_published_at');
    }
}
