"""
사용자 모델
"""
from sqlalchemy import Column, String, Boolean, DateTime, Text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from datetime import datetime
import uuid

from ..core.database import Base


class User(Base):
    """사용자 모델"""
    __tablename__ = "users"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
    email = Column(String(255), unique=True, index=True, nullable=False)
    hashed_password = Column(String(255), nullable=False)
    full_name = Column(String(255), nullable=True)
    
    # 상태 관리
    is_active = Column(Boolean, default=True, nullable=False)
    is_admin = Column(Boolean, default=False, nullable=False)
    
    # 타임스탬프
    created_at = Column(DateTime(timezone=True), default=datetime.utcnow, nullable=False)
    updated_at = Column(DateTime(timezone=True), default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
    last_login_at = Column(DateTime(timezone=True), nullable=True)
    
    # 프로필 정보
    bio = Column(Text, nullable=True)
    avatar_url = Column(String(500), nullable=True)
    
    # 설정
    timezone = Column(String(50), default="Asia/Seoul", nullable=False)
    language = Column(String(10), default="ko", nullable=False)
    
    # 관계 설정
    todo_items = relationship("TodoItem", back_populates="user", lazy="dynamic")

    def __repr__(self):
        return f"<User(email='{self.email}', full_name='{self.full_name}')>"
