<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260510110000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute les traductions et routes CMS des pages du page builder.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE page_builder_page ADD route_mode VARCHAR(20) DEFAULT \'cms\' NOT NULL');
        $this->addSql('ALTER TABLE page_builder_page ADD template VARCHAR(64) DEFAULT \'default\' NOT NULL');
        $this->addSql('ALTER TABLE page_builder_page ADD disabled BOOLEAN DEFAULT false NOT NULL');
        $this->addSql('ALTER TABLE page_builder_page ADD published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE page_builder_page ADD un_published_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
        $this->addSql('ALTER TABLE page_builder_page ADD seo_indexable BOOLEAN DEFAULT true NOT NULL');

        $this->addSql('CREATE TABLE page_builder_page_translation (id UUID NOT NULL, translatable_id UUID DEFAULT NULL, title VARCHAR(255) NOT NULL, path VARCHAR(255) DEFAULT \'\' NOT NULL, meta_title VARCHAR(255) DEFAULT NULL, meta_description TEXT DEFAULT NULL, meta_robots VARCHAR(64) DEFAULT NULL, breadcrumb_label VARCHAR(255) DEFAULT NULL, locale VARCHAR(5) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX IDX_4DAF08AE2C2AC5D3 ON page_builder_page_translation (translatable_id)');
        $this->addSql('CREATE UNIQUE INDEX page_builder_page_translation_unique_translation ON page_builder_page_translation (translatable_id, locale)');
        $this->addSql('CREATE UNIQUE INDEX page_builder_page_translation_unique_path ON page_builder_page_translation (locale, path)');
        $this->addSql('COMMENT ON COLUMN page_builder_page_translation.id IS \'(DC2Type:uuid)\'');
        $this->addSql('COMMENT ON COLUMN page_builder_page_translation.translatable_id IS \'(DC2Type:uuid)\'');
        $this->addSql('ALTER TABLE page_builder_page_translation ADD CONSTRAINT FK_4DAF08AE2C2AC5D3 FOREIGN KEY (translatable_id) REFERENCES page_builder_page (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE page_builder_page_translation DROP CONSTRAINT FK_4DAF08AE2C2AC5D3');
        $this->addSql('DROP TABLE page_builder_page_translation');
        $this->addSql('ALTER TABLE page_builder_page DROP route_mode');
        $this->addSql('ALTER TABLE page_builder_page DROP template');
        $this->addSql('ALTER TABLE page_builder_page DROP disabled');
        $this->addSql('ALTER TABLE page_builder_page DROP published_at');
        $this->addSql('ALTER TABLE page_builder_page DROP un_published_at');
        $this->addSql('ALTER TABLE page_builder_page DROP seo_indexable');
    }
}
