# src/chatiss_open_sdk/types.py
from __future__ import annotations

from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, Optional, TypeVar, Literal, Generic

T = TypeVar("T")

APIStatus = Literal["SUCCESS", "FAIL"]


@dataclass
class SuccessResponse(Generic[T]):
    status: Literal["SUCCESS"]
    result: T


@dataclass
class FailResponse:
    status: Literal["FAIL"]
    code: int
    msg: str


@dataclass
class TokenResult:
    token: str
    expiration: datetime


@dataclass
class APIResponse(Generic[T]):
    status: APIStatus
    # success 存在
    result: Optional[T] = None
    # fail 存在
    code: Optional[int] = None
    msg: Optional[str] = None


@dataclass
class TongueCreateRequest:
    original_img: str
    skin_img: str
    gender: int
    birthday: str
    use_flash: bool


@dataclass
class WordArticleParagraph:
    title: str
    content: str


@dataclass
class WordArticleDetailResult:
    id: str
    paragraphs: list[WordArticleParagraph]


@dataclass
class TongueWord:
    article_id: Optional[str]
    title: str


@dataclass
class TongueNmpaTongueResultItem:
    zone: str
    words: list[TongueWord]


@dataclass
class TongueNmpaAskingResultItem:
    category: str
    words: list[TongueWord]


@dataclass
class TongueIndicator:
    name: str
    value: float
    status: str
    status_note: str


@dataclass
class TongueDataItem:
    indicators: list[TongueIndicator]
    zone: str
    viscera: str


@dataclass
class TongueCreateResult:
    id: str
    is_valid: bool
    nmpa_tongue_result: list[TongueNmpaTongueResultItem]
    nmpa_asking_result: list[TongueNmpaAskingResultItem]
    tongue_data: list[TongueDataItem]
    invalid_code: Optional[str]
    invalid_reason: Optional[str]


@dataclass
class TongueEventResult:
    status: APIStatus
    result: Any = None
    code: Optional[int] = None
    msg: Optional[str] = None


@dataclass
class TongueSSEEvent:
    event: str
    data: TongueEventResult
