// const mapRruleToFrequency = (rrule: string) => {
//
// 	switch (frequency) {
// 		case "quotidien":
// 			rrule = "FREQ=DAILY";
// 			break;
// 		case "hebdomadaire":
// 			rrule = "FREQ=WEEKLY";
// 			break;
// 		case "mensuel":
// 			rrule = "FREQ=MONTHLY";
// 			break;
// 		default:
// 			return "";
// 	}
// }

const mapFrequencyToRrule = (
	frequency: "unique" | "quotidien" | "hebdomadaire" | "mensuel",
	frequencyEndDate?: Date,
): string => {
	let rrule = "";

	switch (frequency) {
		case "quotidien":
			rrule = "FREQ=DAILY";
			break;
		case "hebdomadaire":
			rrule = "FREQ=WEEKLY";
			break;
		case "mensuel":
			rrule = "FREQ=MONTHLY";
			break;
		default:
			return "";
	}

	if (frequencyEndDate) {
		const until = frequencyEndDate.getTime();
		const untilDate = new Date(until);
		const epochDateString = untilDate
			.toISOString()
			.replace(/[-:]/g, "")
			.split(".")[0]; // Format as YYYYMMDDTHHmmss
		rrule += `;UNTIL=${epochDateString}`;
	}

	return rrule;
};

export default mapFrequencyToRrule;
