import { PageRank } from "../../prefab/hall/PageRank";
import { BadgeDto } from "./WalletM";
import WsM from "./WsM";

export class RankInfoDto {
  rank: number;
  seasonId: number;
  rankValue: number;
  endTimeAt: number;
  badgeId: number;
}

export class RankDto {
  seasonPog: number;
  dailyGrantPog: number;
  remainPog: number;
  onlineTime: number;
  badgeList: BadgeDto[];
  rankInfo: RankInfoDto;
}

export class RankPlayerDto {
  rank: number;
  seasonId: number;
  rankValue: number;
  endTimeAt: number;
  userName: string;
  badgeId: number;
}

export class RankPeopleResult {
  rankList: RankPlayerDto[];
}

export default class RankM {
  private static _ins: RankM;
  public static get ins(): RankM {
    return (RankM._ins ??= new RankM());
  }

  async rankData(type: number): Promise<RankDto> {
    let protocolId = type == PageRank.RankTypeSeason ? 25001 : 25002;
    let result = await WsM.ins.syncRequest(protocolId, {});
    return result;
  }

  async rankPeoples(type: number, grade: number): Promise<RankPeopleResult> {
    let top = 3;
    let protocolId = type == PageRank.RankTypeSeason ? 25005 : 25006;
    let result = await WsM.ins.syncRequest(protocolId, {
      badgeId: grade,
      top: top,
    });

    // for (let i = 0; i < 10; i++) {
    //   let mock = new RankPlayerDto();
    //   mock.rank = result.rankList.length + 1;
    //   mock.userName = "name" + type + "grade" + grade;
    //   mock.rankValue = i * 53974387;
    //   result.rankList.push(mock);
    // }
    return result;
  }

  async _rank(protocolId: number): Promise<RankDto> {
    let result = await WsM.ins.syncRequest(protocolId, {});
    return result;
  }
}
