"""
간단한 Todo 시스템 모델
"""
from sqlalchemy import Column, String, DateTime, Text, Boolean, Integer, ForeignKey, Enum
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from datetime import datetime
import uuid
import enum

from ..core.database import Base


class TodoCategory(str, enum.Enum):
    """Todo 카테고리"""
    TODO = "todo"
    CALENDAR = "calendar" 
    CHECKLIST = "checklist"


class TodoStatus(str, enum.Enum):
    """Todo 상태"""
    PENDING = "pending"
    IN_PROGRESS = "in_progress"
    COMPLETED = "completed"




class Todo(Base):
    """할일 아이템"""
    __tablename__ = "todos"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
    
    # 기본 정보
    title = Column(String(200), nullable=False)  # 할일 제목
    description = Column(Text, nullable=True)  # 할일 설명
    category = Column(Enum(TodoCategory), nullable=True, default=None)
    status = Column(Enum(TodoStatus), nullable=False, default=TodoStatus.PENDING)
    
    # 시간 관리
    created_at = Column(DateTime(timezone=True), nullable=False, default=datetime.utcnow)
    updated_at = Column(DateTime(timezone=True), nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
    due_date = Column(DateTime(timezone=True), nullable=True)  # 마감일
    completed_at = Column(DateTime(timezone=True), nullable=True)
    
    # 추가 정보
    image_urls = Column(Text, nullable=True)  # 첨부 이미지 URLs (JSON 배열 형태, 최대 5개)
    tags = Column(String(500), nullable=True)  # 태그 (쉼표로 구분)
    
    # 관계
    user = relationship("User", back_populates="todos")

    def __repr__(self):
        return f"<Todo(id={self.id}, title='{self.title}', status='{self.status}')>"
