<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260427120000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute les blocs d’information boutique';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE shop_information_block (id UUID NOT NULL, image_id UUID DEFAULT NULL, action_type VARCHAR(20) DEFAULT \'none\' NOT NULL, button_url TEXT DEFAULT NULL, position INT DEFAULT 0, disabled BOOLEAN DEFAULT FALSE NOT NULL, created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, updated_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE UNIQUE INDEX UNIQ_A420BA433DA5256D ON shop_information_block (image_id)');
        $this->addSql('COMMENT ON COLUMN shop_information_block.id IS \'(DC2Type:uuid)\'');
        $this->addSql('COMMENT ON COLUMN shop_information_block.image_id IS \'(DC2Type:uuid)\'');
        $this->addSql('COMMENT ON COLUMN shop_information_block.created_at IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('COMMENT ON COLUMN shop_information_block.updated_at IS \'(DC2Type:datetime_immutable)\'');

        $this->addSql('CREATE TABLE shop_information_block_translation (id UUID NOT NULL, translatable_id UUID DEFAULT NULL, title VARCHAR(255) NOT NULL, description TEXT NOT NULL, button_label VARCHAR(255) DEFAULT NULL, modal_title VARCHAR(255) DEFAULT NULL, modal_description TEXT DEFAULT NULL, locale VARCHAR(5) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX IDX_3939440C2C2AC5D3 ON shop_information_block_translation (translatable_id)');
        $this->addSql('CREATE UNIQUE INDEX shop_information_block_translation_unique_translation ON shop_information_block_translation (translatable_id, locale)');
        $this->addSql('COMMENT ON COLUMN shop_information_block_translation.id IS \'(DC2Type:uuid)\'');
        $this->addSql('COMMENT ON COLUMN shop_information_block_translation.translatable_id IS \'(DC2Type:uuid)\'');

        $this->addSql('ALTER TABLE shop_information_block ADD CONSTRAINT FK_A420BA433DA5256D FOREIGN KEY (image_id) REFERENCES media_media (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE shop_information_block_translation ADD CONSTRAINT FK_3939440C2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES shop_information_block (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE shop_information_block DROP CONSTRAINT FK_A420BA433DA5256D');
        $this->addSql('ALTER TABLE shop_information_block_translation DROP CONSTRAINT FK_3939440C2C2AC5D3');
        $this->addSql('DROP TABLE shop_information_block');
        $this->addSql('DROP TABLE shop_information_block_translation');
    }
}
