import apiClient from '../../../shared/services/apiClient';

export interface GDPRRequest {
  id: number;
  request_type: 'data_export' | 'data_deletion' | 'data_rectification' | 'consent_withdrawal';
  status: 'pending' | 'processing' | 'completed' | 'rejected' | 'cancelled';
  user_id: number;
  user_email: string;
  created_at: string;
  processed_at?: string;
  verification_token?: string;
  expires_at?: string;
}

class GDPRService {
  async requestDataExport() {
    const response = await apiClient.post('/gdpr/export');
    return response.data;
  }

  async getExportData(requestId: number, verificationToken: string) {
    const response = await apiClient.get(`/gdpr/export/${requestId}`, {
      params: { verification_token: verificationToken },
    });
    return response.data;
  }

  async downloadExport(requestId: number, verificationToken: string) {
    const response = await apiClient.get(`/gdpr/export/${requestId}`, {
      params: { verification_token: verificationToken },
      responseType: 'blob',
    });
    return response.data;
  }

  async requestDataDeletion() {
    const response = await apiClient.post('/gdpr/delete');
    return response.data;
  }

  async confirmDataDeletion(requestId: number, verificationToken: string) {
    const response = await apiClient.post(`/gdpr/delete/${requestId}/confirm`, null, {
      params: { verification_token: verificationToken },
    });
    return response.data;
  }

  async getMyRequests() {
    const response = await apiClient.get('/gdpr/requests');
    return response.data;
  }

  async getAllRequests(filters?: { status?: string; page?: number; limit?: number }) {
    const response = await apiClient.get('/gdpr/admin/requests', { params: filters });
    return response.data;
  }

  async deleteRequest(requestId: number) {
    const response = await apiClient.delete(`/gdpr/admin/requests/${requestId}`);
    return response.data;
  }
}

export default new GDPRService();

