<?php

declare(strict_types=1);

namespace App\Support\Baselines;

use App\Support\Ui\OperatorExplanation\ExplanationFamily;
use App\Support\Ui\OperatorExplanation\TrustworthinessLevel;

enum BaselineCompareReasonCode: string
{
    case NoSubjectsInScope = 'no_subjects_in_scope';
    case CoverageUnproven = 'coverage_unproven';
    case EvidenceCaptureIncomplete = 'evidence_capture_incomplete';
    case UnsupportedSubjects = 'unsupported_subjects';
    case AmbiguousSubjects = 'ambiguous_subjects';
    case StrategyFailed = 'strategy_failed';
    case RolloutDisabled = 'rollout_disabled';
    case NoDriftDetected = 'no_drift_detected';
    case OverdueFindingsRemain = 'overdue_findings_remain';
    case GovernanceExpiring = 'governance_expiring';
    case GovernanceLapsed = 'governance_lapsed';

    public function message(): string
    {
        return match ($this) {
            self::NoSubjectsInScope => 'No subjects were in scope for this comparison.',
            self::CoverageUnproven => 'Coverage proof was missing or incomplete, so some findings were suppressed for safety.',
            self::EvidenceCaptureIncomplete => 'Evidence capture was incomplete, so some drift evaluation may have been suppressed.',
            self::UnsupportedSubjects => 'One or more in-scope subjects could not be compared by the selected strategy.',
            self::AmbiguousSubjects => 'One or more in-scope subjects could not be compared because identity matching stayed ambiguous.',
            self::StrategyFailed => 'One or more in-scope subjects failed during strategy processing, so the compare result is incomplete.',
            self::RolloutDisabled => 'Full-content baseline compare is currently disabled by rollout configuration.',
            self::NoDriftDetected => 'No drift was detected for in-scope subjects.',
            self::OverdueFindingsRemain => 'Overdue findings still need action even though the latest compare did not produce new drift.',
            self::GovernanceExpiring => 'Accepted-risk governance is nearing expiry and needs review.',
            self::GovernanceLapsed => 'Accepted-risk governance has lapsed and needs follow-up.',
        };
    }

    public function explanationFamily(): ExplanationFamily
    {
        return match ($this) {
            self::NoDriftDetected => ExplanationFamily::NoIssuesDetected,
            self::CoverageUnproven,
            self::EvidenceCaptureIncomplete,
            self::UnsupportedSubjects,
            self::AmbiguousSubjects,
            self::RolloutDisabled,
            self::OverdueFindingsRemain,
            self::GovernanceExpiring,
            self::GovernanceLapsed => ExplanationFamily::CompletedButLimited,
            self::StrategyFailed => ExplanationFamily::BlockedPrerequisite,
            self::NoSubjectsInScope => ExplanationFamily::MissingInput,
        };
    }

    public function trustworthinessLevel(): TrustworthinessLevel
    {
        return match ($this) {
            self::NoDriftDetected => TrustworthinessLevel::Trustworthy,
            self::CoverageUnproven,
            self::EvidenceCaptureIncomplete,
            self::UnsupportedSubjects,
            self::AmbiguousSubjects,
            self::OverdueFindingsRemain,
            self::GovernanceExpiring,
            self::GovernanceLapsed => TrustworthinessLevel::LimitedConfidence,
            self::StrategyFailed,
            self::RolloutDisabled,
            self::NoSubjectsInScope => TrustworthinessLevel::Unusable,
        };
    }

    public function absencePattern(): ?string
    {
        return match ($this) {
            self::NoDriftDetected => 'true_no_result',
            self::CoverageUnproven,
            self::EvidenceCaptureIncomplete,
            self::UnsupportedSubjects,
            self::AmbiguousSubjects,
            self::OverdueFindingsRemain,
            self::GovernanceExpiring,
            self::GovernanceLapsed => 'suppressed_output',
            self::StrategyFailed,
            self::RolloutDisabled => 'blocked_prerequisite',
            self::NoSubjectsInScope => 'missing_input',
        };
    }

    public function supportsPositiveClaim(): bool
    {
        return $this === self::NoDriftDetected;
    }
}
