<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260417120000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Create interim_agencies table and add interim_agency_id to employee_contract_periods';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('CREATE TABLE interim_agencies (id SERIAL PRIMARY KEY, name VARCHAR(150) NOT NULL UNIQUE)');
        $this->addSql('ALTER TABLE employee_contract_periods ADD interim_agency_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE employee_contract_periods ADD CONSTRAINT fk_ecp_interim_agency FOREIGN KEY (interim_agency_id) REFERENCES interim_agencies (id) ON DELETE SET NULL');
        $this->addSql('CREATE INDEX idx_ecp_interim_agency ON employee_contract_periods (interim_agency_id)');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE employee_contract_periods DROP CONSTRAINT IF EXISTS fk_ecp_interim_agency');
        $this->addSql('DROP INDEX IF EXISTS idx_ecp_interim_agency');
        $this->addSql('ALTER TABLE employee_contract_periods DROP COLUMN interim_agency_id');
        $this->addSql('DROP TABLE interim_agencies');
    }
}
