<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20260408000000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Add source_observation_id to impact_score for nearest-observation scoring';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE impact_score ADD COLUMN source_observation_id UUID NULL');
        $this->addSql('ALTER TABLE impact_score ADD CONSTRAINT fk_impact_score_observation
            FOREIGN KEY (source_observation_id) REFERENCES sargassum_observation(id) ON DELETE SET NULL');
        $this->addSql('CREATE INDEX idx_impact_score_source_obs ON impact_score (source_observation_id)');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('DROP INDEX idx_impact_score_source_obs');
        $this->addSql('ALTER TABLE impact_score DROP CONSTRAINT fk_impact_score_observation');
        $this->addSql('ALTER TABLE impact_score DROP COLUMN source_observation_id');
    }
}
