import client from '../client';

export interface SuggestionItem {
  id: string;
  analysis_id: string;
  suggestion_type: string;
  risk_level: string;
  params: Record<string, unknown> | null;
  status: string;
  created_at: string;
}

export interface ComparisonReport {
  suggestion_id: string;
  baseline: Record<string, unknown> | null;
  current: Record<string, unknown> | null;
  comparison_available: boolean;
  message?: string;
}

export const suggestionApi = {
  list: async (params?: { analysis_id?: string; status?: string }) => {
    const resp = await client.get('/ai/suggestions', { params });
    return resp.data.data as { data: SuggestionItem[]; total: number };
  },
  approve: async (id: string, action: 'approve' | 'reject') => {
    const resp = await client.post(`/ai/suggestions/${id}/approve`, { action });
    return resp.data.data as { id: string; status: string };
  },
  execute: async (id: string) => {
    const resp = await client.post(`/ai/suggestions/${id}/execute`);
    return resp.data.data as { id: string; status: string };
  },
  getComparison: async (id: string) => {
    const resp = await client.get(`/ai/suggestions/${id}/comparison`);
    return resp.data.data as ComparisonReport;
  },
};
