"""admin 账号管理 + 审计日志 schemas。""" from __future__ import annotations from datetime import datetime from typing import Literal from pydantic import BaseModel, ConfigDict, Field _Role = Literal["super_admin", "finance", "operator"] class AdminCreateRequest(BaseModel): username: str = Field(..., min_length=3, max_length=64) password: str = Field(..., min_length=8, max_length=72) # bcrypt ≤72 字节 role: _Role = "operator" class AdminUpdateRequest(BaseModel): """改角色 / 启用禁用 / 重置密码,字段都可选(只改传了的)。""" role: _Role | None = None status: Literal["active", "disabled"] | None = None password: str | None = Field(None, min_length=8, max_length=72) class AdminAuditLogOut(BaseModel): model_config = ConfigDict(from_attributes=True) id: int admin_id: int admin_username: str action: str target_type: str target_id: str | None = None detail: dict | None = None ip: str | None = None created_at: datetime