"""Define schema models for compliance."""

from pydantic import BaseModel
from typing import Optional
from enum import Enum
# Group related schema definitions so validation rules stay consistent.



class RiskLevel(str, Enum):
    """Define the Risk Level enumeration."""
    high = "high"
    medium = "medium"
    low = "low"


class ComplianceStatus(str, Enum):
    """Define the Compliance Status enumeration."""
    pass_status = "pass"
    warning = "warning"
    fail = "fail"


class Regulation(BaseModel):
    """Define the Regulation API model."""
    id: int
    name: str
    clause: Optional[str] = None
    score: float
    match_keyword: str
    category: RiskLevel
    full_content: str


class ComplianceSegment(BaseModel):
    """Define the Compliance Segment API model."""
    id: int
    index: int
    intent: str
    start_pos: int
    end_pos: int
    content: str
    risk_level: RiskLevel
    regulations: list[Regulation]


class RiskDashboard(BaseModel):
    """Define the Risk Dashboard API model."""
    score: float
    high_risk_count: int
    medium_risk_count: int
    low_risk_count: int
    need_fix_segments: int
    status: ComplianceStatus
    status_label: str


class PriorityAction(BaseModel):
    """Define the Priority Action API model."""
    regulation: str
    issue: str
    suggestion: str
    severity: RiskLevel


class ComplianceResult(BaseModel):
    """Define the Compliance Result API model."""
    task_id: str
    dashboard: RiskDashboard
    segments: list[ComplianceSegment]
    priority_actions: list[PriorityAction]


class ComplianceChatRequest(BaseModel):
    """Define the Compliance Chat Request API model."""
    query: str
    segment_context: Optional[str] = None


class AnalyzeResponse(BaseModel):
    """Define the Analyze Response API model."""
    task_id: str
    status: str = "processing"


class AnalyzeStreamSource(BaseModel):
    """SSE source event payload for analyze-stream."""
    standard: str
    clause: str
    score: float
    status: str
    full_content: str


class AnalyzeStreamFinding(BaseModel):
    """SSE finding event payload for analyze-stream."""
    title: str
    desc: str
    status: str
    clause_ref: Optional[str] = None


class AnalyzeStreamDone(BaseModel):
    """SSE done event payload for analyze-stream."""
    conclusion: str
    actions: list[dict]
    risk_score: int
    highlight_terms: list[str]
    para_text: str