const moment = require("moment");

const DateFormat = "MM/DD/yyyy";
const RuleSets = [
  {
    title: "V1",
    range: [moment("2010-01-01"), moment("2023-04-01")],
  },
  {
    title: "V2",
    range: [moment("2023-04-01"), moment("2024-09-01")],
  },
  {
    title: "V3",
    range: [moment("2024-09-01"), moment("2040-01-01")],
  },
];

function WhichRulesetToApply(close_date) {
  const DateMoment = close_date ? moment(close_date) : moment();
  const newRuleSet = RuleSets.find(
    (r) =>
      DateMoment.isSameOrAfter(r.range[0]) && DateMoment.isBefore(r.range[1])
  );
  //console.log("Using ruleset:", newRuleSet);

  return newRuleSet?.title;
}
exports.WhichRulesetToApply = WhichRulesetToApply;
