from sqlalchemy.ext.asyncio import AsyncSession

from app.models.operation_log import OperationLog
from app.utils.id_gen import generate_id


async def log_operation(
    db: AsyncSession,
    user_id: str,
    username: str,
    action: str,
    method: str,
    path: str,
    detail: str | None = None,
    ip: str | None = None,
):
    log = OperationLog(
        id=generate_id(),
        user_id=user_id,
        username=username,
        action=action,
        method=method,
        path=path,
        detail=detail,
        ip=ip,
    )
    db.add(log)
