<?php

namespace App\Domain\Media\Migrations;

use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\Migration\Migration;

final readonly class UpdateImageVariantsConstraint implements Migration
{
    public function up(ConnectionInterface $connection): void
    {
        // Bestehenden Constraint entfernen
        $connection->execute("ALTER TABLE image_variants DROP INDEX uk_image_variants_combination");

        // Neuen Constraint mit size-Spalte hinzufügen
        $connection->execute("ALTER TABLE image_variants ADD UNIQUE KEY uk_image_variants_combination (image_id, variant_type, size, format)");
    }

    public function down(ConnectionInterface $connection): void
    {
        // Zurück zum ursprünglichen Constraint
        $connection->execute("ALTER TABLE image_variants DROP INDEX uk_image_variants_combination");
        $connection->execute("ALTER TABLE image_variants ADD UNIQUE KEY uk_image_variants_combination (image_id, variant_type, format)");
    }

    public function getVersion(): string
    {
        return "006";
    }

    public function getDescription(): string
    {
        return "Update unique constraint to include size column";
    }
}
