<?php

declare(strict_types=1);

namespace App\Support\Inventory;

use InvalidArgumentException;

final readonly class TenantCoverageTypeTruth
{
    public const string StateSucceeded = InventoryCoverage::StatusSucceeded;

    public const string StateFailed = InventoryCoverage::StatusFailed;

    public const string StateSkipped = InventoryCoverage::StatusSkipped;

    public const string StateUnknown = 'unknown';

    public function __construct(
        public string $key,
        public string $type,
        public string $segment,
        public string $label,
        public string $category,
        public ?string $platform,
        public string $coverageState,
        public bool $followUpRequired,
        public int $followUpPriority,
        public int $observedItemCount,
        public ?int $basisItemCount,
        public ?string $basisErrorCode,
        public ?string $restoreMode,
        public ?string $riskLevel,
        public bool $supportsDependencies,
        public string $followUpGuidance,
        public bool $isBasisPayloadBacked,
    ) {
        if ($this->key === '' || $this->type === '' || $this->label === '') {
            throw new InvalidArgumentException('Coverage truth rows require non-empty identity fields.');
        }
    }

    /**
     * @return array{
     *     __key: string,
     *     key: string,
     *     type: string,
     *     segment: string,
     *     label: string,
     *     category: string,
     *     platform: ?string,
     *     coverage_state: string,
     *     follow_up_required: bool,
     *     follow_up_priority: int,
     *     follow_up_guidance: string,
     *     observed_item_count: int,
     *     basis_item_count: ?int,
     *     basis_error_code: ?string,
     *     restore: ?string,
     *     risk: ?string,
     *     dependencies: bool,
     *     is_basis_payload_backed: bool
     * }
     */
    public function toArray(): array
    {
        return [
            '__key' => $this->key,
            'key' => $this->key,
            'type' => $this->type,
            'segment' => $this->segment,
            'label' => $this->label,
            'category' => $this->category,
            'platform' => $this->platform,
            'coverage_state' => $this->coverageState,
            'follow_up_required' => $this->followUpRequired,
            'follow_up_priority' => $this->followUpPriority,
            'follow_up_guidance' => $this->followUpGuidance,
            'observed_item_count' => $this->observedItemCount,
            'basis_item_count' => $this->basisItemCount,
            'basis_error_code' => $this->basisErrorCode,
            'restore' => $this->restoreMode,
            'risk' => $this->riskLevel,
            'dependencies' => $this->supportsDependencies,
            'is_basis_payload_backed' => $this->isBasisPayloadBacked,
        ];
    }
}
