import { onboardingApi } from './onboarding-client';

//FETCHING CUSTOMER AGREEMENT
export const getCustomerAgreement = async (customerId: string) => {
  const res = await onboardingApi.get(`/customer/get_agreement/${customerId}`);
  return res.data;
};

// UPDATING CUSTOMER AGREEMENT
export const updateCustomerAgreement = async (
  customerId: string,
  payload: {
    agreement_data: string;
    terms_and_conditions_checked: number;
    client_agreement_id: number | null;
  }
) => {
  const res = await onboardingApi.post(
    `/customer/update_agreement/${customerId}/${payload.client_agreement_id}`,
    payload
  );
  return res.data;
};
//FETCHING INTERVIEW QUESTION
export const getInterviewQuestion = async (customeId: string | number) => {
  const res = await onboardingApi.get(`/customer/get_interview_question/${customeId}/KBA`);
  return res.data;
};

//SUBMITTING INTERVIEW QUESTIONS
export const submitInterviewAnswer = async (customerId: string | number, payload: any[]) => {
  const res = await onboardingApi.post(`/customer/submit_interview_answer/${customerId}`, { data: payload });
  return res.data;
};
//GET PLANS
export const getPlans = async () => {
  const res = await onboardingApi.get(`/customer/plans`);
  return res.data.plans;
};
//SUBMIT PLAN
export const selectPlan = async (customerId: string | number, planId: string, id: string | number) => {
  const res = await onboardingApi.post(`/customer/${customerId}/subscription/create`, {
    plan_id: planId,
    payment_method_id: 'pm_card_visa',
    billing_status_id: id,
  });
  return res.data;
};
//API TO GET ITEMS IN DB FROM 3RD-PATRY REPORTS
// export const retriveClientReport = async (customerId: string | number) => {
//   const res = await onboardingApi.get(`/customer/retrive_client_report/${customerId}`)
//   return res.data;
// };
export async function retriveClientReport(customerId: string | number) {
  const res = await onboardingApi.get(`/customer/retrive_client_report/${customerId}`);

  let data = null;
  try {
    data = res; // may fail if empty body
  } catch {
    data = null;
  }

  return {
    status: res.status,
    // ok: res.ok,              
    data,
  };
}

//API TO FETCH ITEMS
export const getItems = async (customerId: string | number) => {
  const res = await onboardingApi.get(`/customer/negative_item_for_verification/${customerId}`)
  return res.data;
};

//API TO CONFIRM DISPUTE ITEMS
export const confirmDisputeItems = async (customerId: string | number, payload: any[]) => {
  const res = await onboardingApi.post(`/customer/submit_verified_item/${customerId}`, { data: payload })
  return res.data;
};
