"""
Task-related schemas.
"""
from typing import Optional, Dict, Any, Literal
from datetime import datetime
from pydantic import BaseModel, Field, ConfigDict
import uuid


class Task(BaseModel):
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    type: Literal['image', 'video', 'audio', 'music', 'script']
    status: str
    created_at: float = Field(default_factory=lambda: datetime.now().timestamp())
    updated_at: float = Field(default_factory=lambda: datetime.now().timestamp())
    model: str
    provider: Optional[str] = None
    params: Dict[str, Any]
    provider_task_id: Optional[str] = None
    result: Optional[Dict[str, Any]] = None
    error: Optional[str] = None

    # Retry configuration
    retry_count: int = 0
    max_retries: int = 3

    # Timestamps for task lifecycle
    started_at: Optional[float] = None
    completed_at: Optional[float] = None

    # User context
    user_id: Optional[str] = None
    project_id: Optional[str] = None

    # Soft delete support
    deleted_at: Optional[float] = None

    model_config = ConfigDict(populate_by_name=True)
