<?php

declare(strict_types=1);

namespace App\Support;

final readonly class OperationTypeResolution
{
    /**
     * @param  list<OperationTypeAlias>  $aliasesConsidered
     */
    public function __construct(
        public string $rawValue,
        public CanonicalOperationType $canonical,
        public array $aliasesConsidered,
        public string $aliasStatus,
        public bool $wasLegacyAlias,
    ) {}

    /**
     * @return array{
     *     raw_value: string,
     *     canonical: array{
     *         canonical_code: string,
     *         domain_key: ?string,
     *         artifact_family: ?string,
     *         display_label: string,
     *         supports_operator_explanation: bool,
     *         expected_duration_seconds: ?int
     *     },
     *     aliases_considered: list<array{
     *         raw_value: string,
     *         canonical_code: string,
     *         alias_status: string,
     *         write_allowed: bool,
     *         deprecation_note: ?string,
     *         retirement_path: ?string
     *     }>,
     *     alias_status: string,
     *     was_legacy_alias: bool
     * }
     */
    public function toArray(): array
    {
        return [
            'raw_value' => $this->rawValue,
            'canonical' => $this->canonical->toArray(),
            'aliases_considered' => array_map(
                static fn (OperationTypeAlias $alias): array => $alias->toArray(),
                $this->aliasesConsidered,
            ),
            'alias_status' => $this->aliasStatus,
            'was_legacy_alias' => $this->wasLegacyAlias,
        ];
    }
}