"""Standalone SDK models mirroring API responses."""

from __future__ import annotations

from enum import Enum
from typing import Any

from pydantic import BaseModel, ConfigDict, Field


class SDKModel(BaseModel):
    """Base model configured for forward compatibility."""

    model_config = ConfigDict(extra="ignore", populate_by_name=True)


class Severity(str, Enum):
    CRITICAL = "critical"
    HIGH = "high"
    MEDIUM = "medium"
    LOW = "low"
    INFO = "info"


class EvidenceLevel(str, Enum):
    FULL = "full"
    PARTIAL = "partial"
    INSUFFICIENT = "insufficient"


class AttestationStatus(str, Enum):
    ATTESTED = "attested"
    ANALYSIS_ONLY = "analysis_only"
    CHAIN_FAILED = "chain_failed"
    IPFS_FAILED = "ipfs_failed"
    FREE = "free"
    METADATA_ONLY = "metadata_only"


class OnChainStatus(str, Enum):
    ATTESTED = "attested"
    NOT_FOUND = "not_found"


class Finding(SDKModel):
    severity: Severity
    category: str
    line: int | None = None
    function: str | None = None
    description: str
    recommendation: str
    references: list[str] = Field(default_factory=list)
    sources: list[str] = Field(default_factory=list)
    confidence: float | None = Field(default=None, ge=0.0, le=1.0)


class ReviewResult(SDKModel):
    score: int = Field(ge=0, le=100)
    evidence_level: EvidenceLevel
    findings: list[Finding] = Field(default_factory=list)
    recommendations: list[str] = Field(default_factory=list)
    severity_counts: dict[str, int] | None = None
    attestation: dict[str, Any] = Field(default_factory=dict)
    attestation_status: AttestationStatus = AttestationStatus.FREE
    ipfs_uri: str | None = None
    confidence: float | None = Field(default=None, ge=0.0, le=1.0)
    tx_hash: str | None = None
    remaining_reviews: int | None = None


class StatusResult(SDKModel):
    request_hash: str
    status: OnChainStatus
    validator_address: str | None = None
    agent_id: int | None = None
    score: int | None = None
    response_hash: str | None = None
    tag: str | None = None
    last_update: int = 0
    response_uri: str | None = None


class ReputationResult(SDKModel):
    agent_id: int
    status: str
    feedback_count: int
    summary_value: int
    summary_value_decimals: int
    summary_value_normalized: str
    client_count: int


class HealthResult(SDKModel):
    status: str
    chain_listener: str
    stake_status: str
    stake_eth: float


class StatsResult(SDKModel):
    total_reviews: int
    avg_score: float
    total_paid: int
    total_free: int
    earnings_usdc: float
    reviews_today: int
