import { PayType } from "../../prefab/common/PayItems";
import PayM from "../mgr/PayM";
import { GoodInfo } from "./UserM";
import WsM from "./WsM";

export class ShopDto {
  public id: number;
  public totalSell: number;
  public dailyUserSell: number;
  public userSell: number;
  public userAdSell: number;
  public dailyUserAdSell: number;
  public seasonId: number;
  public endTimeAt: number;
  public freeAirdropTotal: number;
  public freeAirdropSell: number;
}

export class ShopResult {
  public storeId: number;
  public shopDtoList: ShopDto[];
}

export class BuyResult {
  public goodList: GoodInfo[];
  public changeList: GoodInfo[];
}
export default class ShopM {
  async shardToGamePass() {
    let result: BuyResult = await WsM.ins.syncRequest(21004, {});
    return result;
  }
  async createOrder(id: number, payType: PayType) {
    let currency = "USD";

    let result: string = await WsM.ins.syncRequest(21002, {
      shopId: id,
      currency: currency,
    });

    PayM.ins.jumpToPay(result);
    return result;
  }
  async buyUseAD(id: number, num: number, adPrice: number) {
    let result: BuyResult = await WsM.ins.syncRequest(21003, {
      shopId: id,
      num: num,
      ad: adPrice,
    });
    return result;
  }
  async buyUseGem(shopItemId: number, num: number, gem: number) {
    let result: BuyResult = await WsM.ins.syncRequest(21003, {
      shopId: shopItemId,
      num: num,
      diamond: gem,
    });

    return result;
  }
  private static _ins: ShopM;
  public static get ins(): ShopM {
    return (ShopM._ins ??= new ShopM());
  }

  async getShopListByStoreId(storeId: number): Promise<ShopDto[]> {
    let result: ShopResult = await WsM.ins.syncRequest(21001, {
      storeId: storeId,
    });
    if (!result) {
      return [];
    }
    return result.shopDtoList;
  }

  async openBox(goodId: number, num: number): Promise<BuyResult> {
    let result = await WsM.ins.syncRequest(21005, {
      goodId: goodId,
      num: num,
    });
    return result;
  }
}
