<?php

declare(strict_types=1);

namespace App\Support\PortfolioTriage;

use App\Support\BackupHealth\TenantBackupHealthAssessment;
use App\Support\Tenants\TenantRecoveryTriagePresentation;

final readonly class PortfolioArrivalContext
{
    /**
     * @param  array{
     *     kind: string,
     *     label: string,
     *     url: string|null,
     *     disabled: bool,
     *     helperText: string|null
     * }  $nextStep
     * @param  array{
     *     kind: string,
     *     label: string,
     *     url: string,
     *     filters: array<string, mixed>|null
     * }|null  $returnTarget
     */
    public function __construct(
        public string $sourceSurface,
        public string $concernFamily,
        public string $concernState,
        public ?string $concernReason,
        public string $arrivalSummary,
        public ?string $claimBoundary,
        public array $nextStep,
        public ?array $returnTarget,
        public ?string $currentTruthDelta,
    ) {}

    public function sourceLabel(): string
    {
        return match ($this->sourceSurface) {
            PortfolioArrivalContextToken::SOURCE_WORKSPACE_OVERVIEW => 'Workspace overview triage',
            PortfolioArrivalContextToken::SOURCE_TENANT_REGISTRY => 'ManagedEnvironment registry triage',
            default => 'Portfolio triage',
        };
    }

    public function concernFamilyLabel(): string
    {
        return match ($this->concernFamily) {
            PortfolioArrivalContextToken::FAMILY_BACKUP_HEALTH => 'Backup health',
            PortfolioArrivalContextToken::FAMILY_RECOVERY_EVIDENCE => 'Recovery evidence',
            default => 'Portfolio concern',
        };
    }

    public function concernStateLabel(): string
    {
        return match ($this->concernState) {
            TenantBackupHealthAssessment::POSTURE_ABSENT => 'Absent',
            TenantBackupHealthAssessment::POSTURE_STALE => 'Stale',
            TenantBackupHealthAssessment::POSTURE_DEGRADED => 'Degraded',
            TenantRecoveryTriagePresentation::RECOVERY_EVIDENCE_UNVALIDATED => 'Unvalidated',
            TenantRecoveryTriagePresentation::RECOVERY_EVIDENCE_WEAKENED => 'Weakened',
            TenantRecoveryTriagePresentation::RECOVERY_EVIDENCE_NO_RECENT_ISSUES_VISIBLE => 'No recent issues visible',
            default => ucfirst(str_replace('_', ' ', $this->concernState)),
        };
    }
}
