import { VALIDATION_ERROR_CODE as a } from "@accelbyte/sdk";
import n from "axios";
import { z as i } from "zod";
import { LoginErrorParam as c } from "@accelbyte/sdk-iam";
class t {
  static errorToString(s) {
    return JSON.stringify(s, Object.getOwnPropertyNames(s));
  }
  static isAxiosError(s) {
    return !!s && !!s.config;
  }
  static isAxiosNetworkError(s) {
    return t.isAxiosError(s) && (!s.response || s.code === n.AxiosError.ERR_NETWORK);
  }
  static isAxiosServerError(s) {
    var o, r;
    if (s instanceof n.AxiosError && ((o = s.response) != null && o.status)) {
      const e = (r = s.response) == null ? void 0 : r.status;
      return t.isAxiosError(s) && e >= 500 && e <= 599;
    }
    return !1;
  }
  static isLoginSessionExpired(s) {
    return s.message === c.Enum.login_session_expired;
  }
  static extractServiceErrorCode(s) {
    var o;
    if (t.isAxiosError(s) && ((o = s == null ? void 0 : s.response) != null && o.data)) {
      const r = s.response.data;
      if (u.safeParse(r).success)
        return r.errorCode;
      if (E.safeParse(r).success)
        return r.ErrorCode;
    }
    return null;
  }
  static isInputValidationError(s) {
    return t.isAxiosError(s) && t.extractServiceErrorCode(s) === a;
  }
}
const E = i.object({
  ErrorCode: i.number(),
  ErrorMessage: i.string()
}), u = i.object({
  errorCode: i.number(),
  errorMessage: i.string()
});
export {
  t as ErrorHelper
};
