/**
 * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
 * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
 */
import { eventCodeEnum } from "../types";
export var ERRORMESSAGE = {
  DOMAIN_NOT_IN_WHITE_LIST: {
    code: eventCodeEnum.SDK_INTERNAL_ERROR,
    message: 'Origin of the message is not in the white list'
  },
  NOT_JSON_FORMAT: {
    code: eventCodeEnum.SDK_INTERNAL_ERROR,
    message: 'The message string should conform to the json format'
  },
  SDK_COMPATIBILITY_ISSUES: {
    code: eventCodeEnum.SDK_INTERNAL_ERROR,
    BROWSER_NOT_SUPPORT_POSTMESSAGE: {
      code: eventCodeEnum.SDK_INTERNAL_ERROR,
      message: 'The browser does not support the postmessage communication mode'
    },
    FAILED_TO_CREATE_IFRAME: {
      code: eventCodeEnum.SDK_INTERNAL_ERROR,
      message: 'Failed to create iframe'
    }
  },
  INIT_PARAMETER_ERROR: {
    code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
    UI_MODE_NOT_SUPPORTED: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'This UI mode is not supported'
    },
    ENVIRONMENT_ERROR: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'The current input environment does not support or is not in the standard enumeration'
    },
    MODE_ERROR: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'mode value not in enum'
    },
    LOCALE_ERROR: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'The current input language does not support or is not in the standard enumeration'
    },
    NET_MODE_NOT_SUPPORT: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'The network mode is not supported'
    },
    EVENT_ERROR: {
      code: eventCodeEnum.SDK_INIT_PARAMETER_ERROR,
      message: 'Parameter type should be function'
    }
  },
  CREATEPAYMENT_PARAMETER_ERROR: {
    code: eventCodeEnum.SDK_CREATEPAYMENT_PARAMETER_ERROR
  },
  CREATECOMPONENT_ERROR: {
    code: eventCodeEnum.SDK_CREATECOMPONENT_ERROR,
    message: 'Failed to create component',
    SINGLETON_COMPONENT_ERROR: {
      code: eventCodeEnum.SDK_CREATECOMPONENT_ERROR,
      message: 'Only one component can be rendered simultaneously'
    },
    LOAD_APP_TIMEOUT: {
      code: eventCodeEnum.SDK_CREATECOMPONENT_ERROR,
      message: 'Load resource timeout'
    },
    NETWORK_REQUEST_ERROR: {
      code: eventCodeEnum.SDK_CREATECOMPONENT_ERROR,
      message: 'Network request error'
    }
  },
  SDK_LAUNCH_PAYMENT_APP_ERROR: {
    code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
    CALL_APP_URL_ERROR: {
      code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
      message: 'Failed to launch app'
    },
    LOAD_APP_TIME_OUT: {
      code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
      message: 'Load app time out'
    },
    CONTAINER_NOT_EXIST: {
      code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
      message: 'Container service does not exist'
    }
  },
  SDK_SUBMIT_ERROR: {
    code: eventCodeEnum.SDK_LAUNCH_PAYMENT_APP_ERROR,
    message: 'Component not created or current browser compatibility issue, not supported'
  },
  PARAM_INVALID: {
    code: 'PARAM_INVALID',
    message: 'An error occurred. The transaction cannot be initiated.'
  },
  UI_STATE_ERROR: {
    code: 'UI_STATE_ERROR',
    message: 'An error occurred. The transaction cannot be initiated.'
  },
  INITIALIZE_TIMEOUT: {
    code: 'INITIALIZE_TIMEOUT',
    API: {
      code: 'INITIALIZE_API_TIMEOUT',
      message: 'An error occurred. The transaction cannot be initiated.'
    },
    WEB: {
      code: 'INITIALIZE_WEB_TIMEOUT',
      message: 'An error occurred; the transaction cannot be initiated.'
    }
  },
  ERR_DATA_STRUCT_UNRECOGNIZED: {
    code: 'ERR_DATA_STRUCT_UNRECOGNIZED',
    message: 'An error occurred. The transaction cannot be initiated.'
  },
  /**
  @deprecated 已废弃 请使用SDK_LAUNCH_PAYMENT_APP_ERROR
  */
  SDK_CALL_URL_ERROR: {
    code: eventCodeEnum.SDK_CALL_URL_ERROR,
    REDIRECT_ERROR: {
      code: eventCodeEnum.SDK_CALL_URL_ERROR,
      message: 'Redirect data exception'
    }
  }
};

// as const satisfies Record<string, ErrorMessage>;

export var BASEPLUGINID = 'CHECKOUT';
export var COMPONENTPLUGINID = 'COMPONENT';
export var EVENT = {
  ready: {
    name: 'onReady',
    uniqueKey: 'userOnReady'
  },
  error: {
    name: 'onError',
    uniqueKey: 'userOnError'
  },
  paymentMethodSelected: {
    name: 'onPaymentMethodSelected',
    uniqueKey: 'userOnPaymentMethodSelected'
  },
  sizeChanged: {
    name: 'onSizeChanged',
    uniqueKey: 'userOnSizeChanged'
  },
  log: {
    name: 'onLog',
    uniqueKey: 'userOnLog'
  },
  launch: {
    name: 'onLaunch'
  },
  redirect: {
    name: 'onRedirect'
  },
  close: {
    name: 'onClose',
    uniqueKey: 'userOnClose'
  },
  destroy: {
    name: 'onDestroy'
  },
  // 标记 SDK 回调事件
  closeCallback: {
    name: 'onCloseCallback',
    uniqueKey: 'closeCallback'
  },
  eventCallback: {
    name: 'onEventCallback',
    uniqueKey: 'userEventCallback'
  },
  submitForm: {
    name: 'submitForm'
  },
  hideCloseButton: {
    name: 'hideCloseButton'
  },
  showCloseButton: {
    name: 'showCloseButton'
  },
  setMaskCloseButton: {
    name: 'setMaskCloseButton'
  },
  setAllowRetention: {
    name: 'setAllowRetention'
  },
  declareCheckoutInfo: {
    name: 'declareCheckoutInfo'
  },
  showPopup: {
    name: 'showPopup'
  },
  dismissLoading: {
    name: 'dismissLoading'
  },
  popupWindow: {
    name: 'popupWindow'
  },
  popWindow: {
    name: 'popWindow'
  },
  getDeviceId: {
    name: 'getDeviceId'
  },
  declareEventCallbackInfo: {
    name: 'declareEventCallbackInfo'
  },
  setGlobalData: {
    name: 'setGlobalData'
  },
  getGlobalData: {
    name: 'getGlobalData'
  },
  /**
   * @deprecated 已废弃 请使用eventCallback
   */
  sendMuitiAppEventToSdk: {
    name: 'sendMuitiAppEventToSdk'
  },
  // deprecated
  receiveMuitiAppFromSdk: {
    name: 'receiveMuitiAppFromSdk'
  },
  sendBroadcast: {
    name: 'sendBroadcast'
  },
  receiveBroadcast: {
    name: 'receiveBroadcast'
  },
  getUserAgentFromSdk: {
    name: 'getUserAgentFromSdk'
  },
  appHeartBeat: {
    name: 'appHeartBeat'
  },
  beforeSubmit: {
    name: 'beforeSubmit',
    uniqueKey: 'userBeforeSubmit'
  },
  beforeSubmitDone: {
    name: 'beforeSubmitDone',
    uniqueKey: 'userBeforeSubmitDone'
  },
  onChange: {
    name: 'onChange',
    uniqueKey: 'userChange'
  },
  getGooglePayToken: {
    name: 'getGooglePayToken'
  },
  initSecuritySDK: {
    name: 'initSecuritySDK'
  },
  closePaymentPolling: {
    name: 'closePaymentPolling'
  },
  onPollingEnd: {
    name: 'onPollingEnd'
  },
  getApplePayToken: {
    name: 'getApplePayToken'
  },
  updated: {
    name: 'updated'
  },
  webAppReady: {
    name: 'webAppReady'
  },
  showToast: {
    name: 'showToast'
  },
  getSdkVersion: {
    name: 'getSdkVersion'
  },
  inputFocus: {
    name: 'onInputFocus'
  },
  /**
   * 通过SDK转发web应用消息给其他web应用(用于iframe之间消息互通)
   * TODO 推荐使用BusManager
   */
  messageForward: {
    name: 'onMessageForward'
  },
  // Element支付完成后事件
  submitPromiseCallback: {
    name: 'onSubmitPayCallback'
  },
  validateFieldsResult: {
    name: 'validateFieldsResult',
    forwardName: 'validateFieldsResultForward',
    uniqueKey: 'uservalidateFieldsResult'
  },
  canIUse: {
    name: 'canIUse'
  }
};

// 2025.09新增，非全量SDK发送事件码
export var SENDEVENT = {
  validateFields: {
    name: 'validateFields'
  }
};
export var COMPONENT_CONTAINER_ID = 'ams-component-container';
export var COMPONENT_SECTION_ID = 'ams-component-section';
export var COMPONENT_IFRAME_TAG_ID = 'ams-checkout-component';
export var COMPONENT_CLOSE_BLOCK_ID = 'asm-component-close-block';
export var COMPONENT_CLOSE_MASK_BLOCK_ID = 'ams-component-mask-close-block';
export var COMPONENT_RETENTION_ID = 'ams-component-retention';
export var MOCKUP_ID = 'ams-component-mockup';
export var LOADING_ID = 'ams-component-loading';
export var POPUPLOADING_ID = 'ams-component-popup-loading'; // popup弹窗loading
export var LISTENER_PREFIX = '_ams_sdk_component_listener';
export var INLINE_BASE_STYLE_ID = 'ams-inline-component-style';
export var INLINE_IMG_CLASSNAME = 'inline-loading';
export var AMSPOPUP_PREFIX = 'ams-popup';
export var LOADTIME_LIMIT = 15000;
export var POPUP_LOADTIME_LOG_LIMIT = 3000;
export var ANIMATION_TIME = 300;
export var TIMEOUT_WEB_APP_HEART_BEAT = 6000;
export var TIME_DELAY_SEND_HEART_BEAT = 1000;
export var closeImg = 'https://cdn.marmot-cloud.com/storage/2023/5/18/1692a487-99b5-4314-9d6f-e9814bc1ca41.svg';
export var closeImgLight = 'https://cdn.marmot-cloud.com/storage/2025/05/24/50891cd3-7a4a-47c0-b550-2e2ce6187c31.svg';
export var LOADINGIMG = 'data:image/png;base64,iVBORw0KGgoAAA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vXTBMtHDHtvI4yy1yQ4IHDbfquuMZMcfJMYmPhn3sIQE13JGTVaEJsHCGS6CGy6o0ykN1CrkcWjjDJVDDIwm34g69McUKSIDjnSHj4PNiEpWKWyoNWelewXEoCuhj5EPpEzeEVFa3L3X1bgHaKOQcjOOD0YFXqYtSCRkDEPW7ApbjMJExZ5LasyCIW8M9mBZ4FQLkHB7G2MfzJ3Q8eKyGtVIsFlcKvBwayfh/ldW8Ck4Va7USEorFAkEoi1zu3KQrEu+Ca6wwi54GpFmYeC6ruLRAgffCLVgv2EchwkuGgGVZWe15bElAL5FeUwSUBR1f5AQUESCQR2mVh1FkjfAkohJgLj1GEVtZIRFACP0fCm/AgmdREnzYqIRhFHkvq+J77MBFQpEPpCQOYPcntwIWeK6Mu0P9D9pzJq4u5hj+AAAAAElFTkSuQmCC';

/**
 * @description Promise回调code映射
 */
export var PROMISE_CALLBACK_CODE = {
  SUCCESS: {
    code: 'SUCCESS'
  },
  UNKNOWN_EXCEPTION: {
    code: 'UNKNOWN_EXCEPTION',
    message: 'Unknown exception. Please check the payment status and contact the merchant.'
  },
  REPEAT_REQ_REJECT: {
    code: 'REPEAT_REQ_REJECT',
    message: 'The order status is abnormal. Please check the payment status and contact the merchant.'
  },
  PROCESS_FAIL: {
    code: 'PROCESS_FAIL',
    message: 'Unknown exception. Please check the payment status and contact the merchant.'
  },
  INQUIRY_PAYMENT_SESSION_FAILED: {
    code: 'INQUIRY_PAYMENT_SESSION_FAILED',
    message: 'The order status is abnormal. Please check the payment status and contact the merchant.'
  }
};