const allowedReminderMinutes = [10, 60, 1440];

function reminderMinutes(value, fallback = 60) {
  const minutes = Number(value);
  return allowedReminderMinutes.includes(minutes) ? minutes : fallback;
}

function scheduledReminderAt(sessionAt, minutes) {
  const session = new Date(sessionAt);

  if (Number.isNaN(session.getTime())) {
    throw new Error("Session time is invalid");
  }

  return new Date(session.getTime() - reminderMinutes(minutes) * 60 * 1000);
}

module.exports = { allowedReminderMinutes, reminderMinutes, scheduledReminderAt };
