57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
from datetime import datetime
|
|
from typing import Literal
|
|
|
|
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
|
|
|
|
ReadingType = Literal["palm", "face", "bazi"]
|
|
ReadingStatus = Literal["pending", "processing", "completed", "failed"]
|
|
|
|
|
|
class BaziInput(BaseModel):
|
|
nickname: str | None = None
|
|
gender: str | None = None
|
|
calendar_type: Literal["solar", "lunar"] = "solar"
|
|
is_leap_month: bool = False
|
|
birth_date: str
|
|
birth_time: str | None = None
|
|
time_unknown: bool = False
|
|
birth_place: str | None = None
|
|
|
|
|
|
class ReadingCreate(BaseModel):
|
|
reading_type: ReadingType
|
|
image_id: str | None = None
|
|
input_data: dict = Field(default_factory=dict)
|
|
|
|
@model_validator(mode="after")
|
|
def validate_payload(self):
|
|
if self.reading_type in {"palm", "face"} and not self.image_id:
|
|
raise ValueError("image_id is required for image readings")
|
|
if self.reading_type == "bazi":
|
|
BaziInput.model_validate(self.input_data)
|
|
return self
|
|
|
|
|
|
class ReadingSummary(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: str
|
|
reading_type: str
|
|
status: str
|
|
created_at: datetime
|
|
overall_summary: str | None = None
|
|
|
|
|
|
class ReadingDetail(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: str
|
|
reading_type: str
|
|
status: str
|
|
input_data: dict
|
|
error_message: str | None = None
|
|
report_data: dict | None = None
|
|
created_at: datetime
|
|
updated_at: datetime
|