import { axiosInstance } from "../config/api";
import { CLINIC_TYPE } from "../constants";
import { clinicsData, registeredClinicsData } from "../mock/clinics";

// export const getClinics = (params) => {
//   switch (params.type) {
//     case CLINIC_TYPE.UNREGISTERED:
//       return { data: clinicsData };
//     case CLINIC_TYPE.REGISTERED:
//       return { data: registeredClinicsData };
//     case CLINIC_TYPE.SUBSCRIBED:
//       return { data: registeredClinicsData };
//     default:
//       return { data: clinicsData };
//   }
// };

export const getClinics = (params) => {
  console.log(params);

  let searchParams = new URLSearchParams();
  searchParams.append("size", params?.pagination?.pageSize ?? 10);
  searchParams.append("page", params?.pagination.pageIndex ?? 0);
  searchParams.append("filter_type", params?.type ?? CLINIC_TYPE.REGISTERED);
  searchParams.append("search", params?.globalFilter ?? "");

  let url = `/clinics/?${searchParams.toString()}`;

  return new Promise((resolve, reject) => {
    axiosInstance
      .get(url)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });

};

export const getLatestClinicId = () => {
  const url = `/clinics/latest-id`;
  return new Promise((resolve, reject) => {
    axiosInstance
      .get(url)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });
};

export const getClinicsById = (id) => {
  const url = `/clinics/${id}`;
  return new Promise((resolve, reject) => {
    axiosInstance
      .get(url)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });
};

export const updateClinicStatus = (data) => {
  const url = `/admin/clinic/status`;
  return new Promise((resolve, reject) => {
    axiosInstance
      .put(url, data)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });
};

export const updateClinicDocs = (id, data) => {
  const url = `/clinics/${id}`;
  return new Promise((resolve, reject) => {
    axiosInstance
      .put(url, data)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });
};

export const getClinicsDashboardStatsById = () => {
  const url = `/companies/dashboard-stats`;
  return new Promise((resolve, reject) => {
    axiosInstance
      .get(url)
      .then((response) => resolve(response))
      .catch((err) => reject(err));
  });
};
