const { ccclass, property } = cc._decorator;

@ccclass
export default class LocalStorage extends cc.Component {
  public static setCurrentLevel(value: number) {
    cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "CurrentLevel", value);
  }

  public static getCurrentLevel(): number {
    if (
      cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "CurrentLevel") ==
      null
    ) {
      cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "CurrentLevel", 0);
      return 0;
    } else
      return JSON.parse(
        cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "CurrentLevel")
      );
  }

  public static setHighestLevel(value: number) {
    cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "HighestLevel", value);
  }

  public static getHighestLevel(): number {
    if (
      cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "HighestLevel") ==
      null
    ) {
      cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "HighestLevel", 1);
      return 1;
    } else
      return JSON.parse(
        cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "HighestLevel")
      );
  }

  public static getStarAtLevel(level: number): number {
    if (
      cc.sys.localStorage.getItem(
        "SaveTheDoge" + " - " + "Level " + level.toString()
      ) == null
    ) {
      cc.sys.localStorage.setItem(
        "SaveTheDoge" + " - " + "Level " + level.toString(),
        0
      );
      return 0;
    } else
      return JSON.parse(
        cc.sys.localStorage.getItem(
          "SaveTheDoge" + " - " + "Level " + level.toString()
        )
      );
  }

  public static setStarAtLevel(level: number, starValue: number) {
    cc.sys.localStorage.setItem(
      "SaveTheDoge" + " - " + "Level " + level.toString(),
      starValue
    );
  }

  public static getAllStar(): number {
    if (
      cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "AllStar") == null
    ) {
      cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "AllStar", 0);
      return 0;
    } else
      return JSON.parse(
        cc.sys.localStorage.getItem("SaveTheDoge" + " - " + "AllStar")
      );
  }

  public static setAllStar() {
    cc.sys.localStorage.setItem("SaveTheDoge" + " - " + "AllStar");
  }
}
