{"version":3,"sources":["../src/models/simulation.model.ts"],"sourcesContent":["import { concatMap, delay, from, of } from \"rxjs\";\nimport { Periodicity } from \"../constants\";\nimport { TimeHelper } from \"../helpers\";\nimport { SimulationScenario } from \"./simulation-scenario.model\";\nimport { Timeline } from \"./timeline.model\";\n\nexport class Simulation {\n  name: string;\n\n  timeline: Timeline;\n  periodicity = Periodicity.DAY;\n  simulationScenarios: SimulationScenario[] = [];\n\n  isFinished = false;\n  isRunning = false;\n\n  constructor(name: string, startMoment?: Date, finishMoment?: Date) {\n    this.name = name;\n\n    this.timeline = new Timeline(startMoment, finishMoment);\n  }\n\n  addScenario(scenario: SimulationScenario) {\n    if (this.isRunning)\n      throw new Error(\n        \"You cannot add new simulation scenarios to started simulations\"\n      );\n\n    if (this.isFinished)\n      throw new Error(\n        \"You cannot add new simulation scenarios to finished simulations\"\n      );\n\n    this.simulationScenarios.push(scenario);\n  }\n\n  run() {\n    this.isRunning = true;\n\n    this.#timeflows();\n\n    this.isRunning = false;\n    this.isFinished = true;\n  }\n\n  #timeflows() {\n    const timeChunks = TimeHelper.calculateTimeIntervals(\n      this.timeline,\n      this.periodicity\n    );\n\n    const flowingTime = from(timeChunks);\n\n    flowingTime\n      .pipe(concatMap((item) => of(item).pipe(delay(1000))))\n      .subscribe((timeChunk) => {\n        console.log(timeChunk);\n      });\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,SAAS,WAAW,OAAO,MAAM,UAAU;AAA3C,IAMa;AANb;AAAA;AAAA;AACA;AACA;AAEA;AAEO,IAAM,aAAN,MAAiB;AAAA,MACtB;AAAA,MAEA;AAAA,MACA;AAAA,MACA,sBAA4C,CAAC;AAAA,MAE7C,aAAa;AAAA,MACb,YAAY;AAAA,MAEZ,YAAY,MAAc,aAAoB,cAAqB;AACjE,aAAK,OAAO;AAEZ,aAAK,WAAW,IAAI,SAAS,aAAa,YAAY;AAAA,MACxD;AAAA,MAEA,YAAY,UAA8B;AACxC,YAAI,KAAK;AACP,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAEF,YAAI,KAAK;AACP,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAEF,aAAK,oBAAoB,KAAK,QAAQ;AAAA,MACxC;AAAA,MAEA,MAAM;AACJ,aAAK,YAAY;AAEjB,aAAK,WAAW;AAEhB,aAAK,YAAY;AACjB,aAAK,aAAa;AAAA,MACpB;AAAA,MAEA,aAAa;AACX,cAAM,aAAa,WAAW;AAAA,UAC5B,KAAK;AAAA,UACL,KAAK;AAAA,QACP;AAEA,cAAM,cAAc,KAAK,UAAU;AAEnC,oBACG,KAAK,UAAU,CAAC,SAAS,GAAG,IAAI,EAAE,KAAK,MAAM,GAAI,CAAC,CAAC,CAAC,EACpD,UAAU,CAAC,cAAc;AACxB,kBAAQ,IAAI,SAAS;AAAA,QACvB,CAAC;AAAA,MACL;AAAA,IACF;AAAA;AAAA;","names":[]}