from datetime import datetime
from typing import Optional

# Pydantic v1/v2 Kompatibilität
try:
    from pydantic import BaseModel, ConfigDict  # v2
    _V2 = True
except ImportError:  # v1
    from pydantic import BaseModel  # type: ignore
    _V2 = False


class AuditLogOut(BaseModel):
    id: int
    user_id: Optional[int] = None
    timestamp: Optional[datetime] = None
    # WICHTIG: frei als String, kein zu enges Enum -> verhindert ResponseValidationError
    action: str
    info: Optional[str] = None
    old_balance_cents: Optional[int] = None
    new_balance_cents: Optional[int] = None

    if _V2:
        # Pydantic v2
        model_config = ConfigDict(from_attributes=True)
    else:
        # Pydantic v1
        class Config:
            orm_mode = True
