from pydantic import BaseModel, Field, field_validator
from typing import Optional
from datetime import datetime, timezone
from langchain.prompts import PromptTemplate

class promptTempleta(BaseModel):
    id: Optional[int] = Field(default=None, description="模板ID")
    name: Optional[str] = Field(default="", description="模板名称")
    description: Optional[str] = Field(default="", description="模板描述")
    content: str = Field(default="", min_length=1, description="模板内容")
    created_at: str = Field(
        default_factory=lambda: datetime.now(timezone.utc).isoformat(),
        description="记录创建时间"
    )

    @field_validator('content')
    def validate_content(cls, value):
        if not "document_slice" in PromptTemplate.from_template(value).input_variables:
            raise ValueError("模板变量缺少 document_slice")
        return value