from sqlalchemy import Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from app.models.base import Base, TimestampMixin


class OperationLog(Base, TimestampMixin):
    __tablename__ = "operation_logs"

    id: Mapped[str] = mapped_column(String(32), primary_key=True)
    user_id: Mapped[str] = mapped_column(String(32), index=True)
    username: Mapped[str] = mapped_column(String(64))
    action: Mapped[str] = mapped_column(String(128))  # e.g. "创建用户", "修改菜单"
    method: Mapped[str] = mapped_column(String(10))  # POST/PUT/DELETE
    path: Mapped[str] = mapped_column(String(256))
    detail: Mapped[str | None] = mapped_column(Text, nullable=True)  # JSON detail
    ip: Mapped[str | None] = mapped_column(String(64), nullable=True)
