import { makeRequest } from "@frontend/kitui";
import { parseAxiosError } from "@root/utils/parse-error";

const API_URL = `${process.env.REACT_APP_DOMAIN}/customer/v1.0.1`;

type GetRecentlyPurchasedTariffsResponse = {
  id: string;
};

export const getRecentlyPurchasedTariffs = async (): Promise<
  [GetRecentlyPurchasedTariffsResponse[] | null, string?]
> => {
  try {
    debugger;
    const recentlyPurchased = await makeRequest<
      never,
      GetRecentlyPurchasedTariffsResponse[]
    >({
      method: "GET",
      url: `${API_URL}/recent`,
      useToken: true,
    });

    return [recentlyPurchased];
  } catch (nativeError) {
    const [error] = parseAxiosError(nativeError);

    return [null, `Не удалось получить историю. ${error}`];
  }
};
