import PayM from "../mgr/PayM";
import WsM from "./WsM";

export interface RechargeDto {
  id: number;
  firstRecharge: number;
}

export interface RechargeResult {
  rechargeDtoList: RechargeDto[];
}

export default class RechargeM {
  async createOrder(currency: string, rechargeId: number) {
    let result: string = await WsM.ins.syncRequest(22001, {
      currency,
      rechargeId,
    });
    PayM.ins.jumpToPay(result);
    return result;
  }
  private static _ins: RechargeM;
  public static get ins(): RechargeM {
    return (RechargeM._ins ??= new RechargeM());
  }

  public async getRechargeList(): Promise<RechargeDto[]> {
    let result: RechargeResult = await WsM.ins.syncRequest(22002, {});
    if (result.rechargeDtoList) {
      return result.rechargeDtoList;
    }
    return [];
  }
}
