import { api as client } from "../auth/http";
import { unwrap } from "@/utils/endpoint";
import { URL_CONSTANTS } from "@/constants/URLS";
import type {
  IOverviewBillingTab,
  IOverviewBookingsTab,
  IOverviewCustomersTab,
  IOverviewDashboard,
  IOverviewOperationsTab,
  IOverviewStaffTab,
  OverviewRange,
} from "@/types/overview";

const O = URL_CONSTANTS.OVERVIEW;

export const overviewService = {
  getDashboard: async (range?: OverviewRange): Promise<IOverviewDashboard> => {
    const response = await client.get<IOverviewDashboard>(O.BASE, {
      params: range ? { range } : undefined,
    });
    return unwrap(response);
  },

  getBookingsTab: async (range?: OverviewRange): Promise<IOverviewBookingsTab> => {
    const response = await client.get<IOverviewBookingsTab>(O.BOOKINGS, {
      params: range ? { range } : undefined,
    });
    return unwrap(response);
  },

  getBillingTab: async (range?: OverviewRange): Promise<IOverviewBillingTab> => {
    const response = await client.get<IOverviewBillingTab>(O.BILLING, {
      params: range ? { range } : undefined,
    });
    return unwrap(response);
  },

  getOperationsTab: async (): Promise<IOverviewOperationsTab> => {
    const response = await client.get<IOverviewOperationsTab>(O.OPERATIONS);
    return unwrap(response);
  },

  getCustomersTab: async (range?: OverviewRange): Promise<IOverviewCustomersTab> => {
    const response = await client.get<IOverviewCustomersTab>(O.CUSTOMERS, {
      params: range ? { range } : undefined,
    });
    return unwrap(response);
  },

  getStaffTab: async (range?: OverviewRange): Promise<IOverviewStaffTab> => {
    const response = await client.get<IOverviewStaffTab>(O.STAFF, {
      params: range ? { range } : undefined,
    });
    return unwrap(response);
  },
};
