"""Shared helpers for contract adapters."""

from __future__ import annotations

from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
    from iqtoolkit_contracts import AIProvider, SeverityLevel


def map_impact_to_severity(impact_score: Optional[float]) -> "SeverityLevel":
    from iqtoolkit_contracts import SeverityLevel

    if impact_score is None:
        return SeverityLevel.INFO
    if impact_score >= 70:
        return SeverityLevel.CRITICAL
    if impact_score >= 50:
        return SeverityLevel.HIGH
    if impact_score >= 30:
        return SeverityLevel.MEDIUM
    return SeverityLevel.LOW


def map_provider(provider: Optional[str]) -> Optional["AIProvider"]:
    if not provider:
        return None

    from iqtoolkit_contracts import AIProvider

    normalized = provider.lower()
    if normalized in {"openai", "azure", "bedrock", "claude", "ollama", "gemini"}:
        return AIProvider(normalized)
    return None
