/**
 * Service for compliance reporting
 */
import apiClient from '../../../shared/services/apiClient';

export interface ComplianceReport {
  period: {
    start_date: string;
    end_date: string;
  };
  financial_audit: {
    total_actions: number;
    description: string;
  };
  gdpr_compliance: {
    total_requests: number;
    completed_requests: number;
    completion_rate: number;
    description: string;
  };
  security_audit: {
    total_events: number;
    description: string;
  };
  compliance_status: string;
  generated_at: string;
  generated_by: string;
}

export interface GDPRSummary {
  total_requests: number;
  pending_requests: number;
  completed_requests: number;
  completion_rate: number;
  requests_by_type: Record<string, number>;
  compliance_status: string;
}

const complianceService = {
  /**
   * Get compliance report
   */
  async getComplianceReport(startDate?: string, endDate?: string, format: 'json' | 'csv' = 'json') {
    const params = new URLSearchParams();
    if (startDate) params.append('start_date', startDate);
    if (endDate) params.append('end_date', endDate);
    params.append('format', format);

    const response = await apiClient.get(`/compliance/report?${params.toString()}`, {
      responseType: format === 'csv' ? 'blob' : 'json',
    });
    return response.data;
  },

  /**
   * Get GDPR compliance summary
   */
  async getGDPRSummary() {
    const response = await apiClient.get('/compliance/gdpr-summary');
    return response.data;
  },
};

export default complianceService;

