"""
Review workflow context objects for Gar
코드 리뷰 에이전트들이 공유하는 설정과 상태를 캡슐화
"""

from __future__ import annotations

from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import Any


class ReviewMode(str, Enum):
    """Gar가 지원하는 리뷰 모드"""

    NORMAL = "normal"
    SECURITY = "security"
    INTERFACE = "interface"
    API_SECURITY = "api_security"


@dataclass(frozen=True)
class ReviewConfig:
    """LLM 및 리뷰 전역 설정"""

    model: str
    temperature: float
    max_output_tokens: int
    max_retries: int
    language: str | None = None


@dataclass(frozen=True)
class ReviewFlags:
    """리뷰 동작을 제어하는 플래그"""

    quiet: bool = False
    show_prompt: bool = False


@dataclass(frozen=True)
class ReviewTarget:
    """리뷰 대상 파일 및 선택적 diff 정보"""

    files: list[Path]
    diff: str | None = None


@dataclass
class ReviewFinding:
    """에이전트가 발견한 단일 리뷰 결과"""

    file: Path | None
    line: int | None
    category: str
    severity: str
    message: str
    suggestion: str | None = None
    extra: dict[str, Any] = field(default_factory=dict)


@dataclass
class ReviewState:
    """리뷰 진행 중의 가변 상태"""

    interface_summary: dict[str, Any] | None = None
    findings: list[ReviewFinding] = field(default_factory=list)
    conversation_log: list[dict[str, str]] = field(default_factory=list)
    input_context: dict[str, Any] | None = None


@dataclass(frozen=True)
class ReviewContext:
    """완전한 리뷰 컨텍스트"""

    mode: ReviewMode
    config: ReviewConfig
    flags: ReviewFlags
    target: ReviewTarget
    state: ReviewState

    # 편의 프로퍼티들 (Gac 스타일)
    @property
    def model(self) -> str:
        return self.config.model

    @property
    def temperature(self) -> float:
        return self.config.temperature

    @property
    def max_output_tokens(self) -> int:
        return self.config.max_output_tokens

    @property
    def max_retries(self) -> int:
        return self.config.max_retries

    @property
    def quiet(self) -> bool:
        return self.flags.quiet


@dataclass(frozen=True)
class ReviewReport:
    """최종 리뷰 결과"""

    mode: ReviewMode
    findings: list[ReviewFinding]
