// ================================================================
// frontend/src/api/types/auditLogs.ts
// ================================================================
/**
 * Audit Log Types - TypeScript interfaces for audit log data
 *
 * Aligned with backend schema:
 * - shared/models/audit_log_schemas.py
 *
 * Last Updated: 2025-11-02
 * Status: ✅ Complete - Aligned with backend
 */

export interface AuditLogResponse {
  id: string;
  tenant_id: string;
  user_id: string | null;
  service_name: string;
  action: string;
  resource_type: string;
  resource_id: string | null;
  severity: 'low' | 'medium' | 'high' | 'critical';
  description: string;
  changes: Record<string, any> | null;
  audit_metadata: Record<string, any> | null;
  endpoint: string | null;
  method: string | null;
  ip_address: string | null;
  user_agent: string | null;
  created_at: string;
}

export interface AuditLogFilters {
  start_date?: string;
  end_date?: string;
  user_id?: string;
  action?: string;
  resource_type?: string;
  severity?: 'low' | 'medium' | 'high' | 'critical';
  search?: string;
  limit?: number;
  offset?: number;
}

export interface AuditLogListResponse {
  items: AuditLogResponse[];
  total: number;
  limit: number;
  offset: number;
  has_more: boolean;
}

export interface AuditLogStatsResponse {
  total_events: number;
  events_by_action: Record<string, number>;
  events_by_severity: Record<string, number>;
  events_by_resource_type: Record<string, number>;
  date_range: {
    min: string | null;
    max: string | null;
  };
}

// Aggregated audit log (combines logs from all services)
export interface AggregatedAuditLog extends AuditLogResponse {
  // All fields from AuditLogResponse, service_name distinguishes the source
}

// Service list for audit log aggregation
export const AUDIT_LOG_SERVICES = [
  'sales',
  'inventory',
  'orders',
  'production',
  'recipes',
  'suppliers',
  'pos',
  'training',
  'notification',
  'external',
  'forecasting',
] as const;

export type AuditLogServiceName = typeof AUDIT_LOG_SERVICES[number];
