<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Bridge\Doctrine\Migrations;

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

final class Version20260604101500 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Renomme la table d audit SocialNetwork.';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
DO $$
BEGIN
    IF to_regclass('public.socialnetwork_socialnetworknew_audit') IS NOT NULL
        AND to_regclass('public.socialnetwork_socialnetwork_audit') IS NULL THEN
        ALTER TABLE socialnetwork_socialnetworknew_audit RENAME TO socialnetwork_socialnetwork_audit;
    END IF;

    IF to_regclass('public.socialnetwork_socialnetworknew_audit_id_seq') IS NOT NULL
        AND to_regclass('public.socialnetwork_socialnetwork_audit_id_seq') IS NULL THEN
        ALTER SEQUENCE socialnetwork_socialnetworknew_audit_id_seq RENAME TO socialnetwork_socialnetwork_audit_id_seq;
    END IF;
END $$;
SQL);
    }

    public function down(Schema $schema): void
    {
        $this->addSql(<<<'SQL'
DO $$
BEGIN
    IF to_regclass('public.socialnetwork_socialnetwork_audit') IS NOT NULL
        AND to_regclass('public.socialnetwork_socialnetworknew_audit') IS NULL THEN
        ALTER TABLE socialnetwork_socialnetwork_audit RENAME TO socialnetwork_socialnetworknew_audit;
    END IF;

    IF to_regclass('public.socialnetwork_socialnetwork_audit_id_seq') IS NOT NULL
        AND to_regclass('public.socialnetwork_socialnetworknew_audit_id_seq') IS NULL THEN
        ALTER SEQUENCE socialnetwork_socialnetwork_audit_id_seq RENAME TO socialnetwork_socialnetworknew_audit_id_seq;
    END IF;
END $$;
SQL);
    }
}
