/**
 * 非标接口返回值
 */
export class ApiResponse<T = any> {
  constructor(resCode: string | number, resMsg?: string, data?: T) {
    this.resCode = resCode;
    this.resMsg = resMsg;
    this.data = data;
  }

  /**
   * 响应代码 0=成功，其他失败
   */
  resCode: string | number;
  resMsg?: string;
  data?: T;

  static success = new ApiResponse("0");

  static isSuccess(res: ApiResponse) {
    return res.resCode === "0" || res.resCode === 0;
  }

  static successWithData(data: any) {
    return new ApiResponse("0", null, data);
  }

  static successWithResMsg(resMsg: any) {
    return new ApiResponse("0", resMsg);
  }

  static failed(resMsg?: string) {
    return new ApiResponse("-1", resMsg);
  }
}
