import { Texture2DModel } from "./texture2D.model";
import { Deserialize } from "../util/deserialize.model";
import { BlueprintGeneratedClassModel } from "./blueprintGeneratedClass.model";
import { QuestPointsOfInterestModel } from "./questPointsOfInterest.model";

export class QuestEntryModel implements Deserialize {
  public QuestID: number;
  public CompletedIcon: Texture2DModel;
  public UncompletedIcon: Texture2DModel;
  public QuestName: string;
  public QuestDescription: string;
  public UnlockFeatNames: string[];
  public CompleteGiveEngramClasses: Array<BlueprintGeneratedClassModel>;
  public QuestPointsOfInterest: Array<QuestPointsOfInterestModel>;

  public deserialize(raw: any): this {
    Object.assign(this, raw);
    this.CompletedIcon = new Texture2DModel().deserialize(raw.CompletedIcon);
    this.UncompletedIcon = new Texture2DModel().deserialize(raw.UncompletedIcon);
    // Some Quests dont have an engram on completion
    if (this.CompleteGiveEngramClasses !== undefined)
      this.CompleteGiveEngramClasses
        = this.CompleteGiveEngramClasses.map(i => new BlueprintGeneratedClassModel().deserialize(i));
    // Some Quests have no points of interest to complete
    if (this.QuestPointsOfInterest !== undefined)
      this.QuestPointsOfInterest
        = this.QuestPointsOfInterest.map(i => new QuestPointsOfInterestModel().deserialize(i));
    return this;
  }

  public toJSON() {
    let json = Object.assign({}, this);
    if (this.CompleteGiveEngramClasses === undefined) delete json.CompleteGiveEngramClasses;
    if (this.QuestPointsOfInterest === undefined) delete json.QuestPointsOfInterest;
    return json;
  }
}