import apiClient from './client'

export interface AuditLog {
  id: number
  entityType: string
  entityId: number
  action: string
  description?: string
  oldValues?: string
  newValues?: string
  changedFields?: string
  userId?: number
  userName?: string
  organizationalUnitId?: number
  organizationalUnitName?: string
  timestamp: string
  ipAddress?: string
  userAgent?: string
  requestPath?: string
  isSuccess: boolean
  errorMessage?: string
}

export interface AuditLogQueryParams {
  entityType?: string
  action?: string
  userId?: number
  organizationalUnitId?: number
  fromDate?: string
  toDate?: string
  pageNumber?: number
  pageSize?: number
}

export interface PagedResult<T> {
  items: T[]
  totalCount: number
  pageNumber: number
  pageSize: number
  totalPages: number
}

export const auditLogsApi = {
  async getAll(params?: AuditLogQueryParams): Promise<PagedResult<AuditLog>> {
    const response = await apiClient.get<PagedResult<AuditLog>>('/auditlogs', { params })
    return response.data
  },

  async getById(id: number): Promise<AuditLog> {
    const response = await apiClient.get<AuditLog>(`/auditlogs/${id}`)
    return response.data
  }
}
