"""Authentication history model definitions""" from typing import Optional from pydantic import BaseModel, Field, ConfigDict from datetime import datetime from enum import Enum from bson import ObjectId class AuthAction(str, Enum): """Authentication action types""" LOGIN = "login" LOGOUT = "logout" TOKEN_REFRESH = "token_refresh" AUTHORIZATION_CODE = "authorization_code" PASSWORD_RESET = "password_reset" REGISTER = "register" FAILED_LOGIN = "failed_login" class AuthHistoryBase(BaseModel): """Base authentication history model""" user_id: str application_id: Optional[str] = None action: AuthAction ip_address: str user_agent: Optional[str] = None result: str = "success" details: Optional[dict] = None model_config = ConfigDict(use_enum_values=True) class AuthHistoryCreate(AuthHistoryBase): """Authentication history creation model""" pass class AuthHistory(AuthHistoryBase): """Authentication history response model""" id: str = Field(alias="_id") created_at: datetime model_config = ConfigDict( populate_by_name=True, arbitrary_types_allowed=True, json_encoders={ObjectId: str} ) class AuthHistoryInDB(AuthHistory): """Authentication history model in database""" pass