"""Audit service for logging admin actions.""" from typing import Any, Dict, Optional from sqlalchemy.orm import Session from app.models.audit_log import AuditLog def log_action( db: Session, action: str, user_id: int, target_type: str, target_id: int, details: Optional[Dict[str, Any]] = None ) -> AuditLog: """ Log an admin action to the audit log. Args: db: Database session action: Action performed (e.g., 'booking_approved', 'space_created') user_id: ID of the admin user who performed the action target_type: Type of target entity ('booking', 'space', 'user', 'settings') target_id: ID of the target entity details: Optional dictionary with additional information Returns: Created AuditLog instance """ audit_log = AuditLog( action=action, user_id=user_id, target_type=target_type, target_id=target_id, details=details or {} ) db.add(audit_log) db.commit() db.refresh(audit_log) return audit_log