from __future__ import annotations

from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field, field_validator


class LinkedReimbursementDraftJobCreate(BaseModel):
    message: str = Field(min_length=1, max_length=3000, description="生成报销草稿的原始助手请求。")
    context_json: dict[str, Any] = Field(default_factory=dict, description="复用 Orchestrator 的上下文。")
    conversation_id: str = Field(default="", max_length=120, description="前端会话 ID，用于状态恢复。")

    @field_validator("message")
    @classmethod
    def validate_message(cls, value: str) -> str:
        normalized = str(value or "").strip()
        if not normalized:
            raise ValueError("请先选择要关联的申请单。")
        return normalized


class LinkedReimbursementDraftJobRead(BaseModel):
    job_id: str
    status: str
    message: str = ""
    error: str = ""
    run_id: str = ""
    conversation_id: str = ""
    draft_payload: dict[str, Any] | None = None
    created_at: datetime
    updated_at: datetime
