import axios from "../../../config/axios";
import { BuyServiceType, CreateReviewType } from "../types/ServiecTypes";

export const getServiceSuggestedDanak = async () => {
  const { data } = await axios.get(`/danak-services/suggested`);
  return data;
};
export const getCategoriesPublic = async () => {
  const { data } = await axios.get(`/danak-services/categories/public`);
  return data;
};
export const getServicesByCategory = async (categoryId: string) => {
  let query = ``;
  if (categoryId) {
    query = `?categoryId=${categoryId}`;
  }
  const { data } = await axios.get(`/danak-services/public${query}`);
  return data;
};

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

export const buyService = async (params: BuyServiceType) => {
  const { data } = await axios.post(
    `/subscriptions/${params.serviceId}/subscribe`,
    params
  );
  return data;
};
export const getMyServices = async (search: string) => {
  const { data } = await axios.get(`/subscriptions/user?q=${search}`);
  return data;
};

export const createReview = async (params: CreateReviewType) => {
  const { data } = await axios.post(
    `/danak-services/${params.id}/reviews`,
    params
  );
  return data;
};

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