<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\Migrations\Main;

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

final class Version20250219130532 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add a table for storing export generation';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE chill_main_export_generation (id UUID NOT NULL, deleteAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, exportAlias TEXT DEFAULT \'\' NOT NULL, options JSON DEFAULT \'[]\' NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, storedObject_id INT NOT NULL, createdBy_id INT DEFAULT NULL, PRIMARY KEY(id))');
        $this->addSql('CREATE INDEX IDX_E644B77D6C99C13A ON chill_main_export_generation (storedObject_id)');
        $this->addSql('CREATE INDEX IDX_E644B77D3174800F ON chill_main_export_generation (createdBy_id)');
        $this->addSql('COMMENT ON COLUMN chill_main_export_generation.id IS \'(DC2Type:uuid)\'');
        $this->addSql('COMMENT ON COLUMN chill_main_export_generation.deleteAt IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('COMMENT ON COLUMN chill_main_export_generation.createdAt IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D6C99C13A FOREIGN KEY (storedObject_id) REFERENCES chill_doc.stored_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP TABLE chill_main_export_generation');
    }
}
