from typing import Optional
from datetime import datetime
from pydantic import BaseModel
from app.models.login_log import LoginMethod, AuthType

class LoginLogBase(BaseModel):
    mobile: Optional[str] = None
    ip_address: Optional[str] = None
    location: Optional[str] = None
    user_agent: Optional[str] = None
    login_method: Optional[LoginMethod] = LoginMethod.UNIFIED_PAGE
    auth_type: Optional[AuthType] = AuthType.PASSWORD
    is_success: int = 1
    failure_reason: Optional[str] = None

class LoginLogCreate(LoginLogBase):
    user_id: Optional[int] = None

class LoginLogResponse(LoginLogBase):
    id: int
    user_id: Optional[int] = None
    created_at: datetime

    class Config:
        from_attributes = True

class LoginLogListResponse(BaseModel):
    total: int
    items: list[LoginLogResponse]

