<?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\Ticket;

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

final class Version20240423212824 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add endDate and removedBy columns on addressee history (ticket)';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE chill_ticket.addressee_history ADD endDate TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT null');
        $this->addSql('ALTER TABLE chill_ticket.addressee_history ADD removedBy_id INT DEFAULT NULL');
        $this->addSql('COMMENT ON COLUMN chill_ticket.addressee_history.endDate IS \'(DC2Type:datetime_immutable)\'');
        $this->addSql('ALTER TABLE chill_ticket.addressee_history ADD CONSTRAINT FK_434EBDBDB8346CCF FOREIGN KEY (removedBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
        $this->addSql('CREATE INDEX IDX_434EBDBDB8346CCF ON chill_ticket.addressee_history (removedBy_id)');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE chill_ticket.addressee_history DROP CONSTRAINT FK_434EBDBDB8346CCF');
        $this->addSql('DROP INDEX chill_ticket.IDX_434EBDBDB8346CCF');
        $this->addSql('ALTER TABLE chill_ticket.addressee_history DROP endDate');
        $this->addSql('ALTER TABLE chill_ticket.addressee_history DROP removedBy_id');
    }
}
