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

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

export interface RechargeResult {
  rechargeDtoList: RechargeDto[];
}

export class RechargeHistoryItem {
  id: number;
  currency: string;
  amount: number;
  status: number;
  productDesc: string;
  createTime: string;
  updateTime: string;
}
export class RechargeHistoryResult {
  content: RechargeHistoryItem[];
}

export default class RechargeM {
  async getHistoryRecharge(page: number): Promise<RechargeHistoryItem[]> {
    let result: RechargeHistoryResult = await WsM.ins.syncRequest(22003, {
      page,
    });
    if (result && result.content) {
      return result.content;
    }
    // let a = new RechargeHistoryItem();
    // a.id = 1;
    // a.currency = "USD";
    // a.amount = 100;
    // a.status = 1;
    // a.productDesc = null;
    // a.createTime = "2025-07-06T09:26:52.353619";
    let rrr = [];
    // rrr.push(a);
    return rrr;
  }
  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 [];
  }
}
