import moment from "moment";
import { memoize } from "./Memoization";
import { client } from "src/trpc";

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

	try {
		const response = await client.v1.klimafaktoren.query({
			plz,
			genauigkeit: "years",
			startdatum: date,
			enddatum: moment(date).add(2, "years").toDate(),
		});
		return response;
	} catch (e) {
		return null;
	}
});
