import { apiRequest } from '@/shared/api/httpClient';
import type { ApiListResponse } from '@/shared/types/api';
import type {
  PolicyAcknowledgeDto,
  PolicyAcknowledgmentDto,
} from '@/shared/types/policyDocuments';

const POLICY_ACKNOWLEDGMENTS_PATH = '/policy_acknowledgments';

/** The current user's own acknowledgments (optionally for one document). */
export function listMyPolicyAcknowledgments(
  policyDocumentId?: string,
): Promise<ApiListResponse<PolicyAcknowledgmentDto>> {
  const path = policyDocumentId
    ? `${POLICY_ACKNOWLEDGMENTS_PATH}?${new URLSearchParams({ policyDocumentId }).toString()}`
    : POLICY_ACKNOWLEDGMENTS_PATH;
  return apiRequest<ApiListResponse<PolicyAcknowledgmentDto>>(path);
}

export function acknowledgePolicyDocument(
  request: PolicyAcknowledgeDto,
): Promise<PolicyAcknowledgmentDto> {
  return apiRequest<PolicyAcknowledgmentDto>(POLICY_ACKNOWLEDGMENTS_PATH, {
    method: 'POST',
    body: { data: request },
  });
}
