from pydantic import BaseModel, EmailStr, Field
from typing import Optional
from datetime import datetime
from app.models.user import UserRole

# 회원가입 요청
class UserRegister(BaseModel):
    username: str = Field(..., min_length=3, max_length=50)
    email: EmailStr
    password: str = Field(..., min_length=6)
    full_name: Optional[str] = None

# 로그인 요청
class UserLogin(BaseModel):
    username: str
    password: str

# 토큰 응답
class Token(BaseModel):
    access_token: str
    refresh_token: str
    token_type: str = "bearer"
    expires_in: int

# 토큰 페이로드
class TokenPayload(BaseModel):
    sub: str  # user_id
    exp: datetime
    role: UserRole

# 사용자 응답
class UserResponse(BaseModel):
    id: int
    username: str
    email: str
    full_name: Optional[str]
    role: UserRole
    is_active: bool
    created_at: datetime
    last_login: Optional[datetime]
    
    class Config:
        from_attributes = True

# 현재 사용자 정보
class CurrentUser(BaseModel):
    id: int
    username: str
    email: str
    role: UserRole
    is_active: bool
