import moment from "moment";
import { memoize } from "./Memoization.js";
import { api } from "astro-typesafe-api/client"

export const getKlimafaktoren = memoize(async (date: Date, plz: string) => {
	if (!plz || !date) {
		return null;
	}

	try {
		const response = await api.klimafaktoren.GET.fetch({
			plz,
			genauigkeit: "years",
			startdatum: moment(date).utc(true).toDate(),
			enddatum: moment(date).add(2, "years").utc(true).toDate(),
		});
		return response;
	} catch (e) {
		return null;
	}
});
