<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260618090000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Ajoute le nombre maximum de recompenses visibles dans la boutique.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
DO $$
BEGIN
    IF to_regclass('public.shop_shop_config') IS NOT NULL
        AND NOT EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = 'public'
                AND table_name = 'shop_shop_config'
                AND column_name = 'max_awards_visible_in_shop'
        ) THEN
        ALTER TABLE shop_shop_config ADD max_awards_visible_in_shop INT DEFAULT NULL;
    END IF;
END $$;
SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
DO $$
BEGIN
    IF to_regclass('public.shop_shop_config') IS NOT NULL
        AND EXISTS (
            SELECT 1
            FROM information_schema.columns
            WHERE table_schema = 'public'
                AND table_name = 'shop_shop_config'
                AND column_name = 'max_awards_visible_in_shop'
        ) THEN
        ALTER TABLE shop_shop_config DROP COLUMN max_awards_visible_in_shop;
    END IF;
END $$;
SQL);
    }
}
