import api from "../axios";
import { API_ENDPOINTS } from "../endpoints";
import { TChangeInquiryStatusCredentials, TInquiriesResponse } from "../types";

export const inquiriesService = {
  getInquiries: async (
    params?: Record<string, any>,
  ): Promise<TInquiriesResponse> => {
    try {
      return (await api.get(API_ENDPOINTS.INQUIRIES.BASE(), { params })).data;
    } catch (error) {
      console.error("ERROR caught in inquiries service => getInquiries", error);
      throw error;
    }
  },
  deleteInquiry: async (id: string) => {
    try {
      return (await api.delete(API_ENDPOINTS.INQUIRIES.BASE(id))).data;
    } catch (error) {
      console.error(
        "ERROR caught in inquiries service => deleteInquiry",
        error,
      );
      throw error;
    }
  },
  changeInquiryStatus: async ({
    credentials,
    id,
  }: {
    credentials: TChangeInquiryStatusCredentials;
    id: string;
  }) => {
    try {
      return (await api.put(API_ENDPOINTS.INQUIRIES.STATUS(id), credentials))
        .data;
    } catch (error) {
      console.error(
        "ERROR caught in inquiries service => changeInquiryStatus",
        error,
      );
      throw error;
    }
  },
};
