import axios from "../../../config/axios";
import {
  CreatePlanType,
  CreateServiceCategoryType,
  CreateServiceType,
  ToggleStatusCategoryType,
  UpdatePlanType,
} from "../types/ServiceTypes";

export const getAllServicess = async (
  search: string,
  page: number,
  category: string,
  status: string,
  isDanakSuggest?: boolean,
  limit?: number
) => {
  let query = `?page=${page}`;
  if (status) {
    query += `&isActive=${status === "ACTIVE" ? "1" : "0"}`;
  }
  if (category) {
    query += `&categoryId=${category}`;
  }
  if (search) {
    query += `&q=${search}`;
  }

  if (isDanakSuggest !== undefined) {
    query += `&isDanakSuggest=${isDanakSuggest ? "1" : "0"}`;
  }

  if (limit) {
    query += `&limit=${limit}`;
  }

  const { data } = await axios.get(`/danak-services${query}`);
  return data;
};
export const getCategoryParent = async () => {
  const { data } = await axios.get(`/danak-services/categories`);
  return data;
};

export const getAllCategory = async (
  page: number,
  search: string,
  isActive: "active" | "deactive" | ""
) => {
  let query = `?page=${page}&q=${search}`;
  if (isActive) {
    query += `&isActive=${isActive === "active" ? "1" : "0"}`;
  }
  const { data } = await axios.get(`/danak-services/categories/list${query}`);
  return data;
};

export const createServiceCategory = async (
  params: CreateServiceCategoryType
) => {
  const { data } = await axios.post(`/danak-services/categories`, params);
  return data;
};

export const changeStatusCategory = async (
  params: ToggleStatusCategoryType
) => {
  const { data } = await axios.post(
    `/danak-services/categories/toggle-status/${params.id}`
  );
  return data;
};

export const createService = async (params: CreateServiceType) => {
  const { data } = await axios.post(`/danak-services`, params);
  return data;
};

export const uploadSingle = async (params: FormData) => {
  const { data } = await axios.post(`/uploader/single-file`, params);
  return data;
};

export const uploadMultiple = async (params: FormData) => {
  const { data } = await axios.post(`/uploader/multi-file`, params);
  return data;
};

export const toggleStatusService = async (id: string) => {
  const { data } = await axios.post(`/danak-services/toggle-status/${id}`);
  return data;
};

export const createPlan = async (params: CreatePlanType) => {
  const { data } = await axios.post(`/subscriptions`, params);
  return data;
};

export const getPlans = async (serviceId?: string) => {
  const { data } = await axios.get(`/subscriptions/service/${serviceId}`);
  return data;
};

export const planToggleStatus = async (id: string) => {
  const { data } = await axios.post(`/subscriptions/toggle-status/${id}`);
  return data;
};

export const getPlanDetail = async (id?: string) => {
  const { data } = await axios.get(`/subscriptions/${id}`);
  return data;
};

export const updatePlan = async (id: string, params: UpdatePlanType) => {
  const { data } = await axios.patch(`/subscriptions/${id}`, params);
  return data;
};

export const getReviews = async (page: number) => {
  const { data } = await axios.get(`/danak-services/reviews?page=${page}`);
  return data;
};

export const changeStatusReview = async (params: {
  status: string;
  id: string;
}) => {
  const { data } = await axios.patch(
    `/danak-services/reviews/${params.id}/${params.status}`
  );
  return data;
};

export const getServiceDetail = async (id: string) => {
  const { data } = await axios.get(`/danak-services/${id}`);
  return data;
};

export const updateService = async (id: string, params: CreateServiceType) => {
  const { data } = await axios.patch(`/danak-services/${id}`, params);
  return data;
};

export const getCategoryDetail = async (id: string) => {
  const { data } = await axios.get(`/danak-services/categories/${id}`);
  return data;
};

export const updateCategory = async (
  id: string,
  params: CreateServiceCategoryType
) => {
  const { data } = await axios.patch(
    `/danak-services/categories/${id}`,
    params
  );
  return data;
};

export const deleteCategory = async (id: string) => {
  const { data } = await axios.delete(`/danak-services/categories/${id}`);
  return data;
};

export const toggleSliderService = async (id: string) => {
  const { data } = await axios.post(`/danak-services/toggle-slider/${id}`);
  return data;
};
