"""Pydantic schemas for CoordWorkItem."""

from datetime import datetime
from typing import Optional
from uuid import UUID

from pydantic import BaseModel, Field


class CoordWorkItemCreate(BaseModel):
    """Input schema for creating a work item."""

    workflow_id: str = Field(..., description="Parent workflow UUID", max_length=36)
    project_key: str = Field(..., description="Project namespace slug", max_length=200)
    title: str = Field(..., description="Short title", max_length=500)
    description: Optional[str] = Field(None, description="Full description, markdown ok")
    status: str = Field("pending", description="Status: pending, in_progress, blocked, completed, cancelled")
    priority: int = Field(0, description="Higher value = more urgent")
    assigned_session: Optional[str] = Field(None, max_length=200)
    depends_on_id: Optional[str] = Field(None, description="Blocking predecessor item UUID", max_length=36)


class CoordWorkItemUpdate(BaseModel):
    """Input schema for updating a work item. All fields optional."""

    title: Optional[str] = Field(None, max_length=500)
    description: Optional[str] = None
    status: Optional[str] = Field(None, description="Status: pending, in_progress, blocked, completed, cancelled")
    priority: Optional[int] = None
    assigned_session: Optional[str] = Field(None, max_length=200)
    depends_on_id: Optional[str] = Field(None, max_length=36)
    started_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None


class CoordWorkItemResponse(BaseModel):
    """Output schema for a work item."""

    id: UUID
    workflow_id: str
    project_key: str
    title: str
    description: Optional[str]
    status: str
    priority: int
    assigned_session: Optional[str]
    depends_on_id: Optional[str]
    started_at: Optional[datetime]
    completed_at: Optional[datetime]
    created_at: datetime
    updated_at: datetime

    model_config = {"from_attributes": True}
