<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

/**
 * Client portal — phase 3: link notifications to client tickets (additive).
 *
 * - Adds notification.related_ticket_id (FK client_ticket, SET NULL) plus its index,
 *   so a notification can deep-link to the ticket it concerns without breaking the
 *   existing task-based notifications (column is nullable).
 *
 * Lowercase SQL columns; FK/index names mirror Doctrine's generated identifiers.
 * down() reverses.
 */
final class Version20260621130000 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Client portal phase 3: notification.related_ticket_id link to client_ticket (additive)';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE notification ADD related_ticket_id INT DEFAULT NULL');
        $this->addSql('ALTER TABLE notification ADD CONSTRAINT FK_BF5476CA98F144DB FOREIGN KEY (related_ticket_id) REFERENCES client_ticket (id) ON DELETE SET NULL NOT DEFERRABLE');
        $this->addSql('CREATE INDEX idx_notification_related_ticket ON notification (related_ticket_id)');
        $this->addSql("COMMENT ON COLUMN notification.related_ticket_id IS 'Ticket client lie a la notification (FK client_ticket, SET NULL). null = notification non liee a un ticket.'");
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE notification DROP CONSTRAINT FK_BF5476CA98F144DB');
        $this->addSql('DROP INDEX idx_notification_related_ticket');
        $this->addSql('ALTER TABLE notification DROP related_ticket_id');
    }
}
