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

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: moment(date).utc(true).toDate(),
			enddatum: moment(date).add(2, "years").utc(true).toDate(),
		});
		return response;
	} catch (e) {
		return null;
	}
});
