<?php

declare(strict_types=1);

namespace App\Domain\SmartLink\Migrations;

use App\Framework\Database\ConnectionInterface;
use App\Framework\Database\Migration\Migration;
use App\Framework\Database\Migration\MigrationVersion;
use App\Framework\Database\Schema\Blueprint;
use App\Framework\Database\Schema\ForeignKeyAction;
use App\Framework\Database\Schema\Schema;

final readonly class CreateLinkDestinationsTable implements Migration
{
    public function up(ConnectionInterface $connection): void
    {
        $schema = new Schema($connection);

        $schema->create('link_destinations', function (Blueprint $table) {
            $table->string('id', 50)->primary();
            $table->string('link_id', 26);
            $table->string('service_type', 30); // enum: ServiceType
            $table->text('url');
            $table->integer('priority')->default(0);
            $table->boolean('is_default')->default(false);
            $table->timestamp('created_at');

            $table->foreign('link_id')->references('id')->on('smart_links')->onDelete(ForeignKeyAction::CASCADE);
            $table->index('link_id');
            $table->index('service_type');
        });

        $schema->execute();
    }

    public function down(ConnectionInterface $connection): void
    {
        $schema = new Schema($connection);

        $schema->dropIfExists('link_destinations');
        $schema->execute();
    }

    public function getVersion(): MigrationVersion
    {
        return MigrationVersion::fromTimestamp('2025_01_01_000002');
    }

    public function getDescription(): string
    {
        return 'Create link_destinations table for SmartLink service routing';
    }
}
