const debug = require("debug")("edupage:log");
const error = require("debug")("edupage:error");
const RawData = require("../lib/RawData");
const Edupage = require("./Edupage");
debug.log = console.log.bind(console);
class Season extends RawData {
constructor(data = {}, edupage = null) {
super(data);
this.edupage = edupage;
this.id = data.id;
this.fromDate = null;
this.toDate = null;
this.name = data.nazov;
this.halfYear = +data.polrok;
this.index = +data.poradie;
this.supSeason = null;
this.types = data.typy;
this.classificationSeason = null;
this.isClassification = !!data.klasifikacny;
if(this.edupage) Season.prototype.init.call(this);
}
init(edupage = null) {
if(edupage) this.edupage = edupage;
const year = this.edupage.year;
this.fromDate = new Date(this._data.od.replace("Y0", year).replace("Y1", year + 1));
this.toDate = new Date(this._data.do.replace("Y0", year).replace("Y1", year + 1));
this.supSeason = this.edupage.seasons.find(e => e.id == this._data.nadobdobie) || null;
if(this.isClassification) this.classificationSeason = this.edupage.seasons.find(e => e.id == this._data.klasifikacny) || null;
}
}
module.exports = Season;