package com.correx.core.risk

import com.correx.core.approvals.Tier
import com.correx.core.events.risk.RiskAction
import com.correx.core.events.risk.RiskLevel
import com.correx.core.events.risk.RiskSignal

fun RiskLevel.toApprovalTier(): Tier = when (this) {
    RiskLevel.LOW      -> Tier.T1
    RiskLevel.MEDIUM   -> Tier.T2
    RiskLevel.HIGH     -> Tier.T3
    RiskLevel.CRITICAL -> Tier.T4
}

internal fun RiskLevel.toRiskAction(): RiskAction = when (this) {
    RiskLevel.LOW      -> RiskAction.PROCEED
    RiskLevel.MEDIUM   -> RiskAction.PROMPT_USER
    RiskLevel.HIGH     -> RiskAction.PROMPT_USER
    RiskLevel.CRITICAL -> RiskAction.BLOCK
}

internal fun RiskSignal.toRiskLevel(): RiskLevel = when (this) {
    is RiskSignal.ValidationErrors -> RiskLevel.HIGH
    is RiskSignal.CycleWithoutExit -> RiskLevel.MEDIUM
    is RiskSignal.InferenceTimeout -> RiskLevel.MEDIUM
    is RiskSignal.RepeatedFailure  -> RiskLevel.HIGH
}
