<?php

declare(strict_types=1);

namespace App\Framework\Database\Schema\Commands;

use App\Framework\Database\ValueObjects\ColumnName;
use App\Framework\Database\ValueObjects\ConstraintName;

final class DropForeignCommand
{
    /** @var ConstraintName|array<ColumnName> */
    public readonly ConstraintName|array $index;

    public function __construct(string|ConstraintName|ColumnName ...$index)
    {
        // Single constraint name
        if (count($index) === 1 && ($index[0] instanceof ConstraintName || is_string($index[0]))) {
            $this->index = $index[0] instanceof ConstraintName
                ? $index[0]
                : ConstraintName::fromString($index[0]);
        }
        // Multiple column names (array of columns for composite foreign keys)
        else {
            $this->index = array_map(
                fn($col) => $col instanceof ColumnName ? $col : ColumnName::fromString($col),
                $index
            );
        }
    }
}
