// Stores the state of the application, which consists of a choice of quarter
// and a choice of classes within that quarter. (See classes.js for choices.)
// Quarter can also be undefined to represent that none has been selected. The
// list of classes will have each name only included once.
export class Model {

  constructor() {
    this.quarter = undefined;
    this.classes = [];
  }

  // Change the quarter to the given value, which can be undefined.
  resetQuarter(quarter) {
    this.quarter = quarter;
    this.classes = [];
  }

  // Returns whether this class is in the list of classes.
  hasClass(name) {
    return this.classes.indexOf(name) >= 0;
  }

  // Add the given class to the list of classes if not already present.
  addClass(name) {
    const index = this.classes.indexOf(name);
    if (index < 0)
      this.classes.push(name);  // add at the end
  }

  // Removes the given class from the list if currently present.
  removeClass(name) {
    const index = this.classes.indexOf(name);
    if (index >= 0)
      this.classes.splice(index, 1);  // remove that 1 element
  }
}