from datetime import datetime

from pydantic import BaseModel, Field


class ProjectTaskResponse(BaseModel):
    id: str
    task_type: str
    project_id: str
    status: str
    progress: float
    current_step: str
    error_message: str = ""
    user_message: str = ""
    retryable: bool = False
    source_id: str = ""
    template_id: str = ""
    created_at: datetime | None = None
    updated_at: datetime | None = None


class ListProjectTasksResponse(BaseModel):
    items: list[ProjectTaskResponse] = Field(default_factory=list)


class UserTaskResponse(BaseModel):
    """用户级任务响应（跨 project，用于模板模式）。"""

    id: str
    task_type: str
    project_id: str = ""
    template_id: str = ""
    status: str
    progress: float
    current_step: str
    error_message: str = ""
    user_message: str = ""
    retryable: bool = False
    source_id: str = ""
    created_at: datetime | None = None
    updated_at: datetime | None = None


class ListTasksResponse(BaseModel):
    """用户级任务列表响应（GET /api/v1/tasks）。"""

    items: list[UserTaskResponse] = Field(default_factory=list)
