"""Unified tasks request/response schemas."""

from __future__ import annotations

from typing import Any

from pydantic import BaseModel, ConfigDict, Field, field_validator


class TaskCreateRequest(BaseModel):
    """Payload for creating one task in selected/default provider."""

    content: str = Field(..., min_length=1)
    description: str | None = None
    due_string: str | None = None
    provider: str | None = Field(default=None, min_length=1, max_length=64)

    @field_validator("content", "description", "due_string", "provider")
    @classmethod
    def _strip_text_fields(cls, value: str | None) -> str | None:
        if value is None:
            return None
        text = value.strip()
        return text or None


class TodoistTaskRead(BaseModel):
    """Normalized unified task shape (backward compatible name)."""

    model_config = ConfigDict(extra="allow")

    id: str
    content: str
    title: str | None = None
    provider: str | None = None
    description: str | None = None
    due: dict[str, Any] | None = None
    due_date: str | None = None
    due_string: str | None = None
    priority: int | None = None
    completed: bool | None = None
    overdue: bool | None = None


class TaskCompleteResponse(BaseModel):
    """Task completion response."""

    status: str
    task_id: str
    provider: str | None = None


class CoverageTaskSyncResponse(BaseModel):
    """Response for task creation from coverage gaps."""

    engagement_id: int
    provider: str | None = None
    created_tasks: list[str]
    skipped_tasks: list[str]
