import axiosBaseInstance from "./axios-base-instance";

export async function httpGet(pathUrl: any, headers: any) {
  const response = await axiosBaseInstance
    .get(pathUrl, { headers })
    .catch((error) => error.response);
  console.log("Response base svc : ", response);
  if (response?.data.success) {
    return {
      error: false,
      message: "success",
      data: response?.data,
    };
  } else {
    return {
      error: true,
      message: response?.data?.message || null,
      data: null,
    };
  }
}

export async function httpPost(pathUrl: any, headers: any, data: any) {
  const response = await axiosBaseInstance
    .post(pathUrl, data, { headers })
    .catch(function (error) {
      console.log(error);
      return error.response;
    });
  console.log("Response base svc : ", response);
  if (response?.status == 200 || response?.status == 201) {
    return {
      error: false,
      message: "success",
      data: response?.data,
    };
  } else {
    return {
      error: true,
      message: response?.data?.message || response?.data || null,
      data: null,
    };
  }
}
