"""Pydantic schemas for the Tasks plugin."""

from __future__ import annotations

from datetime import datetime
from typing import Any

from pydantic import BaseModel, Field


class TaskCreate(BaseModel):
    """Schema for creating a task."""
    title: str = Field(..., min_length=1, max_length=255)
    description: str | None = None
    status: str = Field(default="open", pattern="^(open|in_progress|done)$")
    priority: str = Field(default="medium", pattern="^(low|medium|high|urgent)$")
    due_date: datetime | None = None
    assigned_to: str | None = None
    contact_id: str | None = None


class TaskUpdate(BaseModel):
    """Schema for updating a task."""
    title: str | None = Field(default=None, min_length=1, max_length=255)
    description: str | None = None
    status: str | None = Field(default=None, pattern="^(open|in_progress|done)$")
    priority: str | None = Field(default=None, pattern="^(low|medium|high|urgent)$")
    due_date: datetime | None = None
    assigned_to: str | None = None
    contact_id: str | None = None


class TaskAssignRequest(BaseModel):
    """Schema for assigning a task."""
    assigned_to: str = Field(..., description="User ID to assign the task to")


class TaskStatusRequest(BaseModel):
    """Schema for updating task status."""
    status: str = Field(..., pattern="^(open|in_progress|done)$")


class TaskResponse(BaseModel):
    """Schema for task response."""
    id: str
    title: str
    description: str | None = None
    status: str
    priority: str
    due_date: datetime | None = None
    assigned_to: str | None = None
    contact_id: str | None = None
    created_by: str | None = None
    created_at: datetime
    updated_at: datetime


class TaskListResponse(BaseModel):
    """Paginated task list response."""
    items: list[TaskResponse]
    total: int
    page: int
    page_size: int
