import { apiRequest } from '@/shared/api/httpClient';
import type { ApiListResponse } from '@/shared/types/api';
import type {
  PolicyDocumentCategory,
  PolicyDocumentDto,
  PolicyDocumentMutationDto,
} from '@/shared/types/policyDocuments';

const POLICY_DOCUMENTS_PATH = '/policy_documents';

export function listPolicyDocuments(
  category: PolicyDocumentCategory,
): Promise<ApiListResponse<PolicyDocumentDto>> {
  const query = new URLSearchParams({ category }).toString();
  return apiRequest<ApiListResponse<PolicyDocumentDto>>(
    `${POLICY_DOCUMENTS_PATH}?${query}`,
  );
}

export function createPolicyDocument(
  request: PolicyDocumentMutationDto,
): Promise<boolean> {
  return apiRequest<boolean>(POLICY_DOCUMENTS_PATH, {
    method: 'POST',
    body: { data: request },
  });
}

export function updatePolicyDocument(
  id: string,
  request: PolicyDocumentMutationDto,
): Promise<boolean> {
  return apiRequest<boolean>(`${POLICY_DOCUMENTS_PATH}/${id}`, {
    method: 'PUT',
    body: { id, data: request },
  });
}

export function deletePolicyDocument(id: string): Promise<boolean> {
  return apiRequest<boolean>(`${POLICY_DOCUMENTS_PATH}/${id}`, {
    method: 'DELETE',
  });
}
