"""Pydantic schemas for CoordTodo."""

from __future__ import annotations

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

from pydantic import BaseModel, Field


class CoordTodoCreate(BaseModel):
    """Input schema for creating a to-do item."""

    text: str = Field(..., description="To-do item text")
    project_key: Optional[str] = Field(None, description="Project scope; NULL = personal", max_length=100)
    parent_id: Optional[UUID] = Field(None, description="Parent to-do ID for sub-tasks")
    assigned_to_user: Optional[str] = Field(None, description="Target user, e.g. 'mike'", max_length=50)
    assigned_to_machine: Optional[str] = Field(None, description="Target hostname", max_length=100)
    auto_created: bool = Field(False, description="True when Claude auto-generated this item")
    source_context: Optional[str] = Field(None, description="Why Claude auto-created this item")
    due_at: Optional[datetime] = Field(None, description="When the item is due")
    created_by_user: str = Field(..., description="User creating the item", max_length=50)
    created_by_machine: str = Field(..., description="Hostname where the item is created", max_length=100)


class CoordTodoUpdate(BaseModel):
    """Input schema for updating a to-do item."""

    text: Optional[str] = None
    status: Optional[str] = Field(None, description="pending / done / cancelled")
    assigned_to_user: Optional[str] = Field(None, max_length=50)
    assigned_to_machine: Optional[str] = Field(None, max_length=100)
    project_key: Optional[str] = Field(None, max_length=100)
    due_at: Optional[datetime] = Field(None, description="When the item is due")
    completed_by: Optional[str] = Field(None, description="Session or user completing the item", max_length=100)


class CoordTodoResponse(BaseModel):
    """Output schema for a to-do item."""

    id: UUID
    text: str
    project_key: Optional[str]
    parent_id: Optional[UUID]
    assigned_to_user: Optional[str]
    assigned_to_machine: Optional[str]
    auto_created: bool
    source_context: Optional[str]
    due_at: Optional[datetime]
    status: str
    completed_at: Optional[datetime]
    completed_by: Optional[str]
    created_by_user: str
    created_by_machine: str
    created_at: datetime
    updated_at: datetime
    subtasks: list[CoordTodoResponse] = Field(default_factory=list)

    model_config = {"from_attributes": True}
