import { Service } from 'egg';
import { addBags, addEquips } from '@pubUtils/itemUtils';
import * as pubUtils from '@pubUtils/util';
import { BagInter, EquipInter } from '@pubUtils/interface';
const csprng = require('csprng');

/**
 * Utils Service
 */
export default class Utils extends Service {
  /**
   * 生成 len 长度的随机字符串
   * @param len 长度
   * @param radix 基数
   */
  public generateStr(len: number, radix = 36) {
    return `${csprng(len, radix)}`;
  }

  public genCode(len: number) {
    return pubUtils.genCode(len)
  }

  public resResult(status: {code: number, simStr: string}, data?, customMsg?: string) {
    return pubUtils.resResult(status, data, customMsg);
  }

  public addBags(roleId: string, roleName: string, data: BagInter) {
    return addBags(roleId, roleName, data);
  }

  public addEquips(roleId: string, roleName: string, weapon: EquipInter) {
    return addEquips(roleId, roleName, weapon);
  }

  public checkActivityData(data: any, type: number) {
    return { data, type }
  }
}
