import createAxios from '@lib/shared/api/http';
import useAgentApi from '@lib/shared/api/modules/agent';
import useClueApi from '@lib/shared/api/modules/clue';
import useContractApi from '@lib/shared/api/modules/contract';
import useCustomerApi from '@lib/shared/api/modules/customer';
import useCustomFormApi from '@lib/shared/api/modules/customForm';
import useDashboard from '@lib/shared/api/modules/dashboard';
import useFollowApi from '@lib/shared/api/modules/follow';
import useHomeApi from '@lib/shared/api/modules/home';
import useOpportunityApi from '@lib/shared/api/modules/opportunity';
import useOrderApi from '@lib/shared/api/modules/order';
import useProductApi from '@lib/shared/api/modules/product';
import useSysApi from '@lib/shared/api/modules/sys';
import useLicenseApi from '@lib/shared/api/modules/system/authorizedManagement';
import useBusinessApi from '@lib/shared/api/modules/system/business';
import useLoginApi from '@lib/shared/api/modules/system/login';
import useMessageApi from '@lib/shared/api/modules/system/message';
import useModuleApi from '@lib/shared/api/modules/system/module';
import useOrgApi from '@lib/shared/api/modules/system/org';
import useProcessApi from '@lib/shared/api/modules/system/process';
import useRoleApi from '@lib/shared/api/modules/system/role';

import useDiscreteApi from '@/hooks/useDiscreteApi';

import checkStatus from '../http/checkStatus';

const { message } = useDiscreteApi();

const CDR = createAxios({
  showErrorMsg: message.error,
  checkStatus,
});

const orgApi = useOrgApi(CDR);
const sysApi = useSysApi(CDR);
const clueApi = useClueApi(CDR);
const roleApi = useRoleApi(CDR);
const homeApi = useHomeApi(CDR);
const loginApi = useLoginApi(CDR);
const agentApi = useAgentApi(CDR);
const moduleApi = useModuleApi(CDR);
const followApi = useFollowApi(CDR);
const productApi = useProductApi(CDR);
const messageApi = useMessageApi(CDR);
const licenseApi = useLicenseApi(CDR);
const customerApi = useCustomerApi(CDR);
const businessApi = useBusinessApi(CDR);
const dashboardApi = useDashboard(CDR);
const opportunityApi = useOpportunityApi(CDR);
const contractApi = useContractApi(CDR);
const orderApi = useOrderApi(CDR);
const customFormApi = useCustomFormApi(CDR);
const processApi = useProcessApi(CDR);

export const {
  addCustomForm,
  updateCustomForm,
  getCustomFormDetail,
  saveCustomFormAdmins,
  getCustomFormAdmins,
  relateCustomFormMember,
  getCustomFormRoles,
  getCustomFormRoleUsers,
  getCustomFormRoleUserDeptTree,
  getCustomFormRoleUserRoleTree,
  removeCustomFormMember,
  getCustomFormList,
  getCustomFormDataDetail,
  getCustomFormDataPage,
  addCustomFormData,
  batchUpdateCustomFormData,
  batchDeleteCustomFormData,
  updateCustomFormData,
  deleteCustomFormData,
  deleteCustomForm,
  enableCustomForm,
  disableCustomForm,
  getCustomFormOptions,
  preCheckImportCustomForm,
  downloadCustomFormTemplate,
  importCustomForm,
  exportCustomFormAll,
  exportCustomFormSelected,
} = customFormApi;

export const {
  getOrderFormConfig,
  getOrderFormSnapshotConfig,
  addOrder,
  getOrderDetail,
  getOrderDetailSnapshot,
  updateOrder,
  batchUpdateOrder,
  deleteOrder,
  getOrderList,
  getOrderInContractList,
  getOrderTab,
  addOrderView,
  updateOrderView,
  getOrderViewList,
  getOrderViewDetail,
  fixedOrderView,
  enableOrderView,
  deleteOrderView,
  dragOrderView,
  updateOrderStatus,
  updateOrderStatusRollback,
  sortOrder,
  sortOrderStatus,
  addOrderStatus,
  getOrderStatusConfig,
  updateOrderStage,
  downloadOrder,
  deleteOrderStatus,
  getOrderStatistic,
  saveAdvanceConfig,
  switchOrderCirculationType,
} = orderApi;

export const {
  getFollowPlanTab,
  deleteFollowPlan,
  updateFollowPlan,
  getFollowPLanPage,
  addFollowPlanView,
  deleteFollowRecord,
  getFollowRecordTab,
  updateFollowRecord,
  addFollowRecord,
  addFollowPlan,
  dragFollowPlanView,
  getFollowPlanDetail,
  getFollowRecordPage,
  addFollowRecordView,
  fixedFollowPlanView,
  dragFollowRecordView,
  updateFollowPlanView,
  enableFollowPlanView,
  deleteFollowPlanView,
  getFollowRecordDetail,
  fixedFollowRecordView,
  getFollowPlanViewList,
  updateFollowPlanStatus,
  updateFollowRecordView,
  enableFollowRecordView,
  deleteFollowRecordView,
  getFollowRecordViewList,
  getFollowPlanViewDetail,
  getFollowRecordViewDetail,
} = followApi;

export const {
  addProduct,
  getProduct,
  deleteProduct,
  updateProduct,
  importProduct,
  getProductList,
  dragSortProduct,
  getProductOptions,
  batchDeleteProduct,
  batchUpdateProduct,
  getProductFormConfig,
  preCheckImportProduct,
  downloadProductTemplate,
  getProductPrice,
  updateProductPrice,
  getProductPriceList,
  addProductPrice,
  deleteProductPrice,
  getProductPriceFormConfig,
  dragSortProductPrice,
  batchUpdateProductPrice,
  downloadProductPriceTemplate,
  exportProductPriceAll,
  exportProductPriceSelected,
  preCheckImportProductPrice,
  importProductPrice,
  copyProductPrice,
} = productApi;

export const {
  deleteOpt,
  getOptTab,
  transferOpt,
  addOpportunity,
  batchDeleteOpt,
  updateOptStage,
  addBusinessView,
  getOptStatistic,
  sortOpportunity,
  getOptFormConfig,
  addOptFollowPlan,
  getOptFollowPlan,
  dragBusinessView,
  updateOpportunity,
  fixedBusinessView,
  preCheckImportOpt,
  importOpportunity,
  getOpportunityList,
  addOptFollowRecord,
  getOptFollowRecord,
  deleteBusinessView,
  updateBusinessView,
  enableBusinessView,
  updateOptFollowPlan,
  deleteOptFollowPlan,
  cancelOptFollowPlan,
  getBusinessViewList,
  globalSearchOptPage,
  downloadOptTemplate,
  addOpportunityStage,
  getOpportunityDetail,
  getOptFollowPlanList,
  exportOpportunityAll,
  sortOpportunityStage,
  deleteOptFollowRecord,
  updateOptFollowRecord,
  getBusinessViewDetail,
  advancedSearchOptPage,
  getOptFollowRecordList,
  batchUpdateOpportunity,
  updateOpportunityStage,
  deleteOpportunityStage,
  advancedSearchOptDetail,
  generateOpportunityChart,
  getOpportunityContactList,
  updateOptFollowPlanStatus,
  exportOpportunitySelected,
  getOpportunityStageConfig,
  updateOpportunityStageRollback,
  getQuotationTab,
  addQuotationView,
  deleteQuotationView,
  fixedQuotationView,
  getQuotationViewDetail,
  getQuotationViewList,
  updateQuotationView,
  enableQuotationView,
  dragQuotationView,
  getQuotationList,
  addQuotation,
  updateQuotation,
  getQuotationDetail,
  getQuotationSnapshotDetail,
  getQuotationFormConfig,
  getQuotationSnapshotFormConfig,
  deleteQuotation,
  approvalQuotation,
  voidQuotation,
  revokeQuotation,
  batchApprove,
  batchVoided,
  batchUpdateQuotation,
  downloadQuotation,
} = opportunityApi;

export const {
  addClue,
  getClue,
  pickClue,
  updateClue,
  deleteClue,
  assignClue,
  getClueTab,
  importLead,
  getClueList,
  getPoolClue,
  addClueView,
  dragClueView,
  batchPickClue,
  exportClueAll,
  fixedClueView,
  transformClue,
  getPoolOptions,
  deleteCluePool,
  moveToLeadPool,
  deleteClueView,
  updateClueView,
  enableClueView,
  batchToCluePool,
  batchDeleteClue,
  getCluePoolList,
  batchAssignClue,
  getClueViewList,
  addLeadPoolView,
  batchUpdateLead,
  updateClueStatus,
  dragLeadPoolView,
  batchTransferClue,
  getClueFormConfig,
  addClueFollowPlan,
  getClueFollowPlan,
  getClueHeaderList,
  getClueViewDetail,
  exportCluePoolAll,
  fixedLeadPoolView,
  generateLeadChart,
  exportClueSelected,
  preCheckImportLead,
  deleteLeadPoolView,
  updateLeadPoolView,
  enableLeadPoolView,
  addClueFollowRecord,
  getClueFollowRecord,
  batchDeleteCluePool,
  batchUpdateCluePool,
  getLeadPoolViewList,
  reTransitionCustomer,
  updateClueFollowPlan,
  deleteClueFollowPlan,
  cancelClueFollowPlan,
  downloadLeadTemplate,
  getClueFollowPlanList,
  getGlobalCluePoolList,
  getLeadPoolViewDetail,
  generateLeadPoolChart,
  ClueTransitionCustomer,
  updateClueFollowRecord,
  deleteClueFollowRecord,
  exportCluePoolSelected,
  getClueFollowRecordList,
  getAdvancedCluePoolList,
  getGlobalSearchClueList,
  getAdvancedSearchClueList,
  updateClueFollowPlanStatus,
  getCluePoolFollowRecordList,
  getAdvancedSearchClueDetail,
  getClueTransitionCustomerList,
} = clueApi;

export const {
  addCustomer,
  getCustomer,
  mergeAccount,
  importAccount,
  importContact,
  updateCustomer,
  deleteCustomer,
  getCustomerTab,
  addContactView,
  getCustomerList,
  addCustomerView,
  dragContactView,
  checkOpportunity,
  fixedContactView,
  dragCustomerView,
  exportContactAll,
  mergeAccountPage,
  batchMoveCustomer,
  getOpenSeaOptions,
  exportCustomerAll,
  fixedCustomerView,
  deleteContactView,
  updateContactView,
  enableContactView,
  addCustomerContact,
  getCustomerContact,
  addCustomerOpenSea,
  getOpenSeaCustomer,
  getCustomerOptions,
  moveCustomerToPool,
  deleteCustomerView,
  updateCustomerView,
  enableCustomerView,
  getContactViewList,
  addAccountPoolView,
  batchUpdateAccount,
  batchUpdateContact,
  batchDeleteCustomer,
  pickOpenSeaCustomer,
  getCustomerViewList,
  dragAccountPoolView,
  saveCustomerRelation,
  getContactViewDetail,
  getGlobalModuleCount,
  fixedAccountPoolView,
  getCustomerFormConfig,
  batchTransferCustomer,
  addCustomerFollowPlan,
  getCustomerFollowPlan,
  updateCustomerContact,
  enableCustomerContact,
  deleteCustomerContact,
  updateCustomerOpenSea,
  switchCustomerOpenSea,
  deleteCustomerOpenSea,
  assignOpenSeaCustomer,
  deleteOpenSeaCustomer,
  getCustomerHeaderList,
  getCustomerContactTab,
  getCustomerViewDetail,
  getGlobalCustomerList,
  exportContactSelected,
  preCheckImportAccount,
  preCheckImportContact,
  deleteAccountPoolView,
  updateAccountPoolView,
  enableAccountPoolView,
  generateCustomerChart,
  getCustomerContactList,
  disableCustomerContact,
  getCustomerOpenSeaList,
  getOpenSeaCustomerList,
  exportCustomerSelected,
  geAdvancedCustomerList,
  getAccountPoolViewList,
  addCustomerFollowRecord,
  getCustomerFollowRecord,
  isCustomerOpenSeaNoPick,
  getCustomerRelationList,
  downloadAccountTemplate,
  downloadContactTemplate,
  updateCustomerFollowPlan,
  deleteCustomerFollowPlan,
  cancelCustomerFollowPlan,
  batchPickOpenSeaCustomer,
  addCustomerCollaboration,
  exportCustomerOpenSeaAll,
  getAccountPoolViewDetail,
  getCustomerFollowPlanList,
  generateCustomerPoolChart,
  updateCustomerFollowRecord,
  deleteCustomerFollowRecord,
  batchDeleteOpenSeaCustomer,
  batchAssignOpenSeaCustomer,
  getCustomerOpportunityPage,
  batchUpdateOpenSeaCustomer,
  getCustomerFollowRecordList,
  getContactListUnderCustomer,
  updateCustomerCollaboration,
  deleteCustomerCollaboration,
  getCustomerContactFormConfig,
  getCustomerCollaborationList,
  getGlobalOpenSeaCustomerList,
  getGlobalCustomerContactList,
  generateCustomerContactChart,
  exportCustomerOpenSeaSelected,
  updateCustomerFollowPlanStatus,
  getAdvancedCustomerContactList,
  getAdvancedOpenSeaCustomerList,
  getCustomerFollowPlanFormConfig,
  batchDeleteCustomerCollaboration,
  getCustomerFollowRecordFormConfig,
  getCustomerOpenSeaFollowRecordList,
  getAccountContract,
  getAccountContractStatistic,
  getAccountPayment,
  getAccountPaymentStatistic,
  getAccountPaymentRecord,
  getAccountPaymentRecordStatistic,
  getCustomerInvoiceList,
  getCustomerOrderList,
  getCustomerInvoiceStatistic,
} = customerApi;

export const {
  exportContractAll,
  exportContractSelected,
  generateContractChart,
  getContractDetail,
  getContractList,
  getContractTab,
  getContractViewDetail,
  getContractViewList,
  addContractView,
  updateContractView,
  fixedContractView,
  enableContractView,
  deleteContractView,
  dragContractView,
  addContract,
  approvalContract,
  revokeContract,
  batchApproveContract,
  batchUpdateContract,
  getContractFormSnapshotConfig,
  updateContract,
  deleteContract,
  changeContractStatus,
  getContractFormConfig,
  getPaymentPlanList,
  getContractPaymentPlanList,
  addPaymentPlan,
  updatePaymentPlan,
  deletePaymentPlan,
  getPaymentPlanDetail,
  getPaymentPlanFormConfig,
  getPaymentPlanTab,
  exportPaymentPlanAll,
  exportPaymentPlanSelected,
  generatePaymentPlanChart,
  addPaymentPlanView,
  updatePaymentPlanView,
  getPaymentPlanViewList,
  getPaymentPlanViewDetail,
  fixedPaymentPlanView,
  enablePaymentPlanView,
  deletePaymentPlanView,
  dragPaymentPlanView,
  getPaymentRecordFormConfig,
  addPaymentRecord,
  updatePaymentRecord,
  getPaymentRecordDetail,
  getPaymentRecordList,
  deletePaymentRecord,
  getPaymentRecordTab,
  exportPaymentRecordAll,
  exportPaymentRecordSelected,
  addPaymentRecordView,
  updatePaymentRecordView,
  getPaymentRecordViewList,
  getPaymentRecordViewDetail,
  fixedPaymentRecordView,
  enablePaymentRecordView,
  deletePaymentRecordView,
  dragPaymentRecordView,
  preCheckImportContractPaymentRecord,
  importContractPaymentRecord,
  downloadContractPaymentRecordTemplate,
  preCheckImportBusinessTitle,
  downloadBusinessTitleTemplate,
  importBusinessTitle,
  getBusinessTitleList,
  addBusinessTitle,
  updateBusinessTitle,
  deleteBusinessTitle,
  revokeBusinessTitle,
  getBusinessTitleDetail,
  getBusinessTitleInvoiceCheck,
  exportBusinessTitleAll,
  exportBusinessTitleSelected,
  getBusinessTitleThirdQuery,
  getBusinessTitleThirdQueryOption,
  getBusinessTitleConfig,
  switchBusinessTitleFormConfig,
  getBusinessTitleModuleForm,
  addInvoiced,
  updateInvoiced,
  deleteInvoiced,
  getInvoicedList,
  getInvoicedDetail,
  getInvoicedFormConfig,
  getInvoicedFormSnapshotConfig,
  exportInvoicedAll,
  exportInvoicedSelected,
  revokeInvoiced,
  approvalInvoiced,
  batchDeleteInvoiced,
  addContractInvoicedView,
  updateContractInvoicedView,
  getContractInvoicedViewList,
  getContractInvoicedViewDetail,
  fixedContractInvoicedView,
  enableContractInvoicedView,
  deleteContractInvoicedView,
  dragContractInvoicedView,
  getInvoicedTab,
  getInvoicedInContractList,
  getContractDetailSnapshot,
  getInvoicedDetailSnapshot,
  getContractStatistic,
  sortContract,
  getPaymentRecordStatistic,
  updateContractStatus,
  updateContractStatusRollback,
  sortContractStatus,
  addContractStatus,
  getContractStatusConfig,
  deleteContractStatus,
  updateContractStage,
  saveContractAdvanceConfig,
  switchContractCirculationType,
} = contractApi;

export const {
  syncDE,
  addApiKey,
  updateAuth,
  createAuth,
  deleteAuth,
  getDEToken,
  getAuthList,
  getDEOrgList,
  updateApiKey,
  enableApiKey,
  deleteApiKey,
  getAuthDetail,
  sendEmailCode,
  getApiKeyList,
  disableApiKey,
  getPageConfig,
  getConfigEmail,
  updateAuthName,
  savePageConfig,
  testConfigEmail,
  getPersonalInfo,
  getThirdTypeList,
  switchThirdParty,
  updateAuthStatus,
  updateConfigEmail,
  getPersonalFollow,
  updatePersonalInfo,
  updateUserPassword,
  cancelCenterExport,
  getExportCenterList,
  getThirdPartyConfig,
  getThirdConfigByType,
  exportCenterDownload,
  getThirdPartyResource,
  getConfigSynchronization,
  testConfigSynchronization,
  updateConfigSynchronization,
  getTenderConfig,
} = businessApi;

export const {
  getMessageTask,
  addAnnouncement,
  saveMessageTask,
  updateAnnouncement,
  deleteAnnouncement,
  getHomeMessageList,
  getAnnouncementList,
  getNotificationList,
  setNotificationRead,
  getNotificationCount,
  batchSaveMessageTask,
  getAnnouncementDetail,
  closeMessageSubscribe,
  getUnReadAnnouncement,
  setAllNotificationRead,
  getMessageTaskConfigDetail,
} = messageApi;

export const {
  addReason,
  sortReason,
  addCluePool,
  addCapacity,
  checkRepeat,
  updateReason,
  searchConfig,
  getReasonList,
  updateCluePool,
  noPickCluePool,
  updateCapacity,
  deleteCapacity,
  uploadTempFile,
  previewPicture,
  getCluePoolPage,
  getCapacityPage,
  addCustomerPool,
  downloadPicture,
  getReasonConfig,
  getSearchConfig,
  getFieldDeptTree,
  getFieldClueList,
  getFieldContractList,
  getFieldInvoiceList,
  getFieldContractPaymentPlanList,
  getFieldContractPaymentRecordList,
  deleteReasonItem,
  deleteAttachment,
  moduleNavListSort,
  getModuleRoleTree,
  deleteOpportunity,
  resetSearchConfig,
  setTopNavListSort,
  setDisplayAdvanced,
  getAdvancedSwitch,
  previewAttachment,
  addOpportunityRule,
  updateCustomerPool,
  deleteCustomerPool,
  noPickCustomerPool,
  updateReasonEnable,
  downloadAttachment,
  getCustomerPoolPage,
  getFormDesignConfig,
  getFieldDeptUerTree,
  getFieldContactList,
  getFieldProductList,
  getModuleTopNavList,
  switchCluePoolStatus,
  deleteModuleCluePool,
  saveFormDesignConfig,
  getFieldCustomerList,
  uploadTempAttachment,
  toggleModuleNavStatus,
  getModuleUserDeptTree,
  updateOpportunityRule,
  getModuleNavConfigList,
  getOpportunityRuleList,
  moduleSearchMaskConfig,
  switchOpportunityStatus,
  getFieldOpportunityList,
  switchCustomerPoolStatus,
  getModuleSearchMaskConfig,
  getFieldPriceList,
  getFieldQuotationList,
  getFieldOrderList,
  getFieldDisplayList,
  getFieldBusinessTitleList,
  getDatasourceRefDetailList,
  getFieldCustomFormList,
  getDatasourceFieldConfig,
} = moduleApi;

export const {
  addUser,
  syncOrg,
  updateUser,
  deleteUser,
  getUserList,
  importUsers,
  setCommander,
  addDepartment,
  getUserDetail,
  batchEditUser,
  getUserOptions,
  getAdminOptions,
  getRoleOptions,
  sortDepartment,
  deleteUserCheck,
  renameDepartment,
  deleteDepartment,
  getDepartmentTree,
  resetUserPassword,
  updateOrgUserName,
  importUserPreCheck,
  getOrgDepartmentUser,
  checkSync,
  batchToggleStatusUser,
  checkDeleteDepartment,
  batchResetUserPassword,
  checkSyncUserFromThird,
} = orgApi;

export const {
  getRoles,
  getUsers,
  updateRole,
  createRole,
  deleteRole,
  getRoleMember,
  getRoleDetail,
  getPermissions,
  getRoleDeptTree,
  relateRoleMember,
  removeRoleMember,
  getRoleMemberTree,
  getRoleDeptUserTree,
  batchRemoveRoleMember,
} = roleApi;

export const { login, signout, isLogin, getKey, getThirdCallback, getThirdOauthCallback } = loginApi;

export const { getSystemVersion, changeLocaleBackEnd } = sysApi;

export const { getLicense, addLicense } = licenseApi;

export const {
  dashboardAdd,
  dashboardPage,
  dashboardDrag,
  dashboardDelete,
  dashboardDetail,
  dashboardRename,
  dashboardUpdate,
  dashboardCollect,
  dashboardModuleAdd,
  dashboardUnCollect,
  dashboardModuleTree,
  dashboardModuleDrag,
  dashboardCollectPage,
  dashboardModuleCount,
  dashboardModuleDelete,
  dashboardModuleRename,
} = dashboardApi;

export const {
  getHomeDepartmentTree,
  getHomeFollowOpportunity,
  getHomeLeadStatistic,
  getHomeSuccessOptStatistic,
  getHomeOpportunityUnderwayStatistic,
} = homeApi;

export const {
  addAgent,
  agentPos,
  updateAgent,
  agentRename,
  agentDelete,
  getAgentPage,
  agentCollect,
  agentModuleAdd,
  unCollectAgent,
  getAgentDetail,
  agentModuleMove,
  getAgentOptions,
  agentModuleRename,
  agentModuleDelete,
  getMkAgentVersion,
  getAgentModuleTree,
  getAgentCollectPage,
  getApplicationScript,
  agentWorkspaceOptions,
  getAgentModuleTreeCount,
  agentApplicationOptions,
  getMkApplication,
} = agentApi;

export const {
  getApprovalProcessList,
  getApprovalPermissions,
  addApprovalProcess,
  updateApprovalProcess,
  approvalProcessDetail,
  deleteApprovalProcess,
  toggleApprovalProcess,
  getApprovalConfigDetail,
  getResourceApprovingDetail,
  reviewResource,
  revokeResource,
  getProcessedApprovalList,
  getPendingApprovalList,
  getInitiatedApprovalList,
  getCcApprovalList,
  rejectApproval,
  backApproval,
  addSignApproval,
  getApprovalResourceDetail,
  getTodoStatistic,
  revokeApproval,
  batchRejectApproval,
  agreeApproval,
  batchAgreeApproval,
  testApprovalWebHook,
} = processApi;
