<?php

declare(strict_types=1);

namespace Plugin\tnt_mcp\src\Mcp\Action;

/**
 * How to find out which row a create produced, so `verify:` can bind `:kVersandart` on an action
 * that was called with id 0. Declared per entry because it is a property of the controller's write
 * order, not of the table.
 */
final class IdResolution
{
    private function __construct(
        public readonly string $table,
        public readonly string $key,
        public readonly IdResolutionMode $mode,
    ) {
    }

    /**
     * @param array<mixed> $raw
     */
    public static function fromArray(array $raw): self
    {
        return new self(
            \is_string($raw['table'] ?? null) ? $raw['table'] : '',
            \is_string($raw['key'] ?? null) ? $raw['key'] : '',
            IdResolutionMode::from(\is_string($raw['mode'] ?? null) ? $raw['mode'] : ''),
        );
    }
}
