import { removeTokenHead } from "@/helper";
import api from "./api";

export const request = {
  sendCode: (mobile, altcha, domain) =>
    api.post(
      "api/v1/user/send-code",
      {
        mobile,
        altcha,
        ...(domain ? { domain } : {}),
      },
      removeTokenHead
    ),
  getUserProfile: (uuid) => api.get(`/api/v1/user-profile/${uuid}`, { requireAuth: true }),
  postUserProfile: (data) => api.post("api/v1/user-profile", data, { requireAuth: true }),
  patchUserProfile: (data, uuid) =>
    api.patch(`api/v1/user-profile/${uuid}`, data, { requireAuth: true }),
  uploadUserAvatar: (file) =>
    api.post("api/v1/user-profile/avatar", file, {
      requireAuth: true,
      headers: {
        "Content-Type": "application/octet-stream",
        "Content-Disposition": `filename="${file?.name || "avatar.jpg"}"`,
      },
    }),
  getUserInfo: (headers) => api.get("oauth/userinfo", { ...headers, requireAuth: true }),
  getInsuranceType: () =>
    api.get(`api/v1/insurances?type=basic`, { requireAuth: true }),
  getSupplementaryInsurance: () =>
    api.get(`api/v1/insurances?type=supplementary`, { requireAuth: true }),
  getDoctors: (params) =>
    api.get("api/v1/doctors", {
      params,
      headers: {
        Authorization: "",
      },
    }),
  getSpecialtyDoctorCounts: (cityId) =>
    api.get("api/v1/specialties/doctor-counts", {
      params: cityId ? { city_id: cityId } : {},
      headers: { Authorization: "" },
    }),
  getAppointmentWeeklySchedule: (uuid) =>
    api.get(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
  postAppointmentWeeklySchedule: () =>
    api.post("api/v1/appointment-settings/weekly-schedule/"),
  patchAppointmentWeeklySchedule: (uuid) =>
    api.patch(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
  deleteAppointmentWeeklySchedule: (uuid) =>
    api.delete(`api/v1/appointment-settings/weekly-schedule/${uuid}`),
  getAppointmentSlots: (doctor_uuid, date) =>
    api.get(
      `api/v1/appointment-slots?doctor_uuid=${doctor_uuid}&date=${date}`,
      removeTokenHead
    ),
  getMonthAvailability: (doctor_uuid, year, month) =>
    api.get(`api/v1/appointment-settings/month-availability/${doctor_uuid}`, {
      params: { year, month },
      ...removeTokenHead,
    }),
  getBookingServices: (doctor_uuid) =>
    api.get(`api/v1/appointment-booking-services/${doctor_uuid}`, removeTokenHead),
  getServiceSlots: (doctor_uuid, date, serviceItemUuids = []) =>
    api.get(
      `api/v1/appointment-service-slots?doctor_uuid=${doctor_uuid}&date=${date}` +
        serviceItemUuids
          .map((u) => `&service_item_uuids[]=${encodeURIComponent(u)}`)
          .join(""),
      removeTokenHead
    ),
  postAppointment: (data) => api.post(`api/v1/appointment`, data, { requireAuth: true }),
  getMyAppointments: (params) => api.get(`api/v1/appointments/user`, { params, requireAuth: true }),
  getPaymentConfig: () => api.get(`api/v1/payment/config`, { requireAuth: true }),
  getPayment: (uuid) => api.get(`api/v1/payment/${uuid}`, { requireAuth: true }),
  getMyPayments: (params) => api.get(`api/v1/my/payments`, { params, requireAuth: true }),
  postDoctor: (data) => api.post("api/v1/doctor", data),
  postImageUpload: (data) =>
    api.post("file/upload/clinic_pro/doctor/field_image", data, {
      headers: {
        "Content-Type": "application/octet-stream",
        "Content-Disposition": `file; filename="${data.name}"`,
        "X-CSRF-Token": "",
      },
    }),
  getDoctorServices: () =>
    api.get("api/v1/categorys/doctor_services", removeTokenHead),
  postDoctorComment: (data) => api.post("api/v1/comment", data, { requireAuth: true }),
  getDoctorClaimInfo: (uuid) => api.get(`api/v1/doctor/${uuid}/claim-info`),
  postDoctorClaim: (uuid, data) =>
    api.post(`api/v1/doctor/${uuid}/claim`, data, { requireAuth: true }),
  deleteDoctor: (uuid) => api.delete(`api/v1/doctor/${uuid}`, { requireAuth: true }),
  getDoctorRate: (uuid) => api.get(`api/v1/rate/${uuid}`),
  getRateEligibility: (uuid) =>
    api.get(`api/v1/rate/${uuid}/eligibility`, { requireAuth: true }),
  getDoctorComments: (uuid) => api.get(`api/v1/comments/${uuid}`),
  postDoctorRate: (data) => api.post("api/v1/rate", data, { requireAuth: true }),
  postCommentsLike: (commentUuid, value) =>
    api.post(`api/v1/like/${commentUuid}`, { value }, { requireAuth: true }),
  getClinicList: (params) =>
    api.get("/api/v1/clinics", {
      params,
      headers: {
        Authorization: "",
      },
    }),
  getDoctorAddress: (location_id) =>
    api.get(`api/v1/clinic-pro/doctor-address/${location_id}`, removeTokenHead),
  getBlogs: (params) =>
    api.get("api/v1/blogs", {
      params,
      headers: {
        Authorization: "",
      },
    }),
  getBlogTags: (params) =>
    api.get("api/v1/tags", {
      params,
      headers: {
        Authorization: "",
      },
    }),
  getTopBlogs: () =>
    api.get("api/v1/blogs/top", {
      headers: {
        Authorization: "",
      },
    }),
  getSingleBlog: (uuid) =>
    api.get(`api/v1/blog/${uuid}`, {
      headers: {
        Authorization: "",
      },
    }),
  getRepresentationInfo: (uuid) =>
    api.get(`api/v1/representation/${uuid}`, { requireAuth: true }),
  getRepresentationDashboardMonthly: (uuid, year, month) =>
    api.get(`api/v1/representation/${uuid}/dashboard/monthly`, {
      params: { year, month },
      requireAuth: true,
    }),
  getRepresentationDashboardYearly: (uuid, year) =>
    api.get(`api/v1/representation/${uuid}/dashboard/yearly`, {
      params: { year },
      requireAuth: true,
    }),
};
