"""
간단한 Todo 시스템 스키마
"""
from pydantic import BaseModel, Field
from typing import List, Optional
from datetime import datetime
from uuid import UUID
from enum import Enum


class TodoCategoryEnum(str, Enum):
    TODO = "todo"
    CALENDAR = "calendar"
    CHECKLIST = "checklist"


class TodoStatusEnum(str, Enum):
    PENDING = "pending"
    IN_PROGRESS = "in_progress"
    COMPLETED = "completed"




class TodoBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=200)
    description: Optional[str] = Field(None, max_length=2000)
    category: Optional[TodoCategoryEnum] = None


class TodoCreate(TodoBase):
    """Todo 생성"""
    due_date: Optional[str] = None  # 문자열로 변경 (한국 시간 형식)
    image_urls: Optional[List[str]] = Field(None, max_items=5, description="최대 5개의 이미지 URL")
    tags: Optional[str] = Field(None, max_length=500)


class TodoUpdate(BaseModel):
    """Todo 수정"""
    title: Optional[str] = Field(None, min_length=1, max_length=200)
    description: Optional[str] = Field(None, max_length=2000)
    category: Optional[TodoCategoryEnum] = None
    status: Optional[TodoStatusEnum] = None
    due_date: Optional[str] = None  # 문자열로 변경 (한국 시간 형식)
    image_urls: Optional[List[str]] = Field(None, max_items=5, description="최대 5개의 이미지 URL")
    tags: Optional[str] = Field(None, max_length=500)


class TodoResponse(BaseModel):
    id: UUID
    user_id: UUID
    title: str
    description: Optional[str] = None
    category: Optional[TodoCategoryEnum] = None
    status: TodoStatusEnum
    created_at: datetime
    updated_at: datetime
    due_date: Optional[str] = None  # 문자열로 변경 (한국 시간 형식)
    completed_at: Optional[datetime] = None
    image_urls: Optional[List[str]] = None
    tags: Optional[str] = None
    
    class Config:
        from_attributes = True


class TodoStats(BaseModel):
    """Todo 통계"""
    total_count: int
    pending_count: int
    in_progress_count: int
    completed_count: int
    completion_rate: float  # 완료율 (%)


class TodoDashboard(BaseModel):
    """Todo 대시보드"""
    stats: TodoStats
    today_todos: List[TodoResponse]
    overdue_todos: List[TodoResponse]
    upcoming_todos: List[TodoResponse]
