import api from "../axios";
import { API_ENDPOINTS } from "../endpoints";
import { ApiResponse } from "../types";
import { TTenderDetails, TTenderResponse } from "../types/Tenders";

export const tendersService = {
  tendersList: async (
    params?: Record<string, any>,
  ): Promise<ApiResponse<TTenderResponse>> => {
    try {
      return (await api.get(API_ENDPOINTS.TENDERS.READ_ALL, { params })).data;
    } catch (error) {
      console.error("ERROR caught in Tenders Services Read all:", error);
      throw error;
    }
  },
  tenderDetails: async (id: string): Promise<ApiResponse<TTenderDetails>> => {
    try {
      return (await api.get(API_ENDPOINTS.TENDERS.DETAILS(id))).data;
    } catch (error) {
      console.error(
        "ERROR caught in Tender Service => tender details: ",
        error,
      );
      throw error;
    }
  },
};
