<?php

declare(strict_types=1);

namespace App\Services\DataForSeo;

use App\Enums\MatchStatus;

final readonly class MatchResult
{
    /**
     * @param  list<MatchCandidate>  $candidates
     */
    public function __construct(
        public MatchStatus $status,
        public ?NormalizedResult $selectedResult,
        public int $score,
        public string $reason,
        public array $candidates,
    ) {}

    public function bestCandidate(): ?MatchCandidate
    {
        return $this->candidates[0] ?? null;
    }

    /**
     * @return list<array<string, mixed>>
     */
    public function candidatesToAuditPayload(): array
    {
        return array_map(
            static fn (MatchCandidate $candidate): array => $candidate->toAuditArray(),
            $this->candidates,
        );
    }
}
