<?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 Version20250718124651 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create join table "chill_ticket.motive_stored_objects"';
    }

    public function up(Schema $schema): void
    {
        $this->addSql(
            <<<'SQL'
            CREATE TABLE chill_ticket.motive_stored_objects (motive_id INT NOT NULL, storedobject_id INT NOT NULL, PRIMARY KEY(motive_id, storedobject_id))
            SQL
        );
        $this->addSql('CREATE INDEX IDX_4247C4849658649C ON chill_ticket.motive_stored_objects (motive_id)');
        $this->addSql('CREATE INDEX IDX_4247C484EE684399 ON chill_ticket.motive_stored_objects (storedobject_id)');
        $this->addSql(
            <<<'SQL'
            ALTER TABLE chill_ticket.motive_stored_objects ADD CONSTRAINT FK_4247C4849658649C FOREIGN KEY (motive_id) REFERENCES chill_ticket.motive (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
            SQL
        );
        $this->addSql(
            <<<'SQL'
            ALTER TABLE chill_ticket.motive_stored_objects ADD CONSTRAINT FK_4247C484EE684399 FOREIGN KEY (storedobject_id) REFERENCES chill_doc.stored_object (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
            SQL
        );
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE chill_ticket.motive_stored_objects DROP CONSTRAINT FK_4247C4849658649C');
        $this->addSql('ALTER TABLE chill_ticket.motive_stored_objects DROP CONSTRAINT FK_4247C484EE684399');
        $this->addSql('DROP TABLE chill_ticket.motive_stored_objects');
    }
}
