export const SESSION_EXPIRED_MESSAGE = '登录已失效，请重新登录';

export interface ErrorMessageSuppressOptions {
  backendErrorCode: string;
  suppressErrorMessage?: boolean;
  logoutCodes: string[];
  modalLogoutCodes: string[];
  expiredTokenCodes: string[];
}

export interface BackendFailDeferOptions {
  suppressErrorMessage?: boolean;
  skipTokenRefresh?: boolean;
}

export function parseServiceCodes(codes?: string) {
  return codes?.split(',').filter(Boolean) || [];
}

export function shouldDeferBackendFailToCaller(options: BackendFailDeferOptions) {
  return Boolean(options.suppressErrorMessage && options.skipTokenRefresh);
}

export function shouldSuppressErrorMessage(options: ErrorMessageSuppressOptions) {
  if (options.suppressErrorMessage) {
    return true;
  }

  const handledCodes = [...options.logoutCodes, ...options.modalLogoutCodes, ...options.expiredTokenCodes];

  return handledCodes.includes(options.backendErrorCode);
}
