import request from "./http";

const urlsConfig = {
  corp: {
    getCorpMemberHomepageInfo: 'getCorpMemberHomepageInfo',
    getCorpMember: 'getCorpMember',
    getCorpMemberOptions: 'getCorpMemberOptions',
    // 企业信息/标签
    getCorpInfo: 'getCorpInfo',
    getCorpTags: 'getCorpTags',
    getTeamBaseInfo: 'getTeamBaseInfo',
    getTeamData: 'getTeamData',
    getTeamById: 'getTeamById',
    getTeamBymember: 'getTeamBymember',
    getCurrentTemplate: 'getCurrentTemplate',
    getTemplateGroup: 'getTemplateGroup',
    getTemplateListByTemptype: 'getTemplateListByTemptype',
    wxAppLogin: 'wxAppLogin',
    getDeptList: 'getRealDeptList',
    getHospitalList: 'getRealHospital',
    addCorpMember: 'addCorpMember',
    getCorpMemberData: 'getCorpMemberData',
    updateCorpMember: 'updateCorpMember',
    addCorpMemberFromWxapp: "addCorpMemberFromWxapp",
    updateCorpMemberFromWxapp: "updateCorpMemberFromWxapp",
    submitCertProfile: 'submitCertProfile',
    getMemberVerifyStatus: "getMemberVerifyStatus",
    getJoinedTeams: "getJoinedTeams",
    updateTeamInfo: "updateTeamInfo",
    createOwnTeam: 'createOwnTeam',
    removeTeammate: "removeTeammate",
    toggleTeamLeaderRole: "toggleTeamLeaderRole",
    joinTheInvitedTeam: 'joinTheInvitedTeam',
    getTeamMemberAvatarsAndName: 'getTeamMemberAvatarsAndName',
    getHlwDeptTree: 'getHlwDeptTree',
    getAllHlwDeptList: "getAllHlwDeptList",
    getHlwHospitalList: 'getHlwHospitalList',
    updateAutoAcceptConsult: 'updateAutoAcceptConsult',
    getAutoAcceptConsult: 'getAutoAcceptConsult',
  },

  knowledgeBase: {
    getArticleByIds: 'getArticleByIds',// 诊断库
    getDisease: 'getDisease',
    getCommonPhrases: 'getCommonPhrases',
    getCommonWordsList: 'getCommonWordsList',
    getCorpCommonWordCate: 'getCorpCommonWordCate',
    getUserCommonWordCate: 'getUserCommonWordCate',
    addUserCommonWordCate: 'addUserCommonWordCate',
    updateUserCommonWordCate: 'updateUserCommonWordCate',
    deleteUserCommonWordCate: 'deleteUserCommonWordCate',
    setCommonWords: 'setCommonWords',
    removeCommonWords: 'removeCommonWords',
    saveCommonPhrase: 'saveCommonPhrase',
    deleteCommonPhrase: 'deleteCommonPhrase',
    getCommonPhraseCategories: 'getCommonPhraseCategories',
    saveCommonPhraseCategory: 'saveCommonPhraseCategory',
    // 宣教文章接口
    getArticleCateList: 'getArticleCateList',
    getArticleList: 'getArticleList',
    getArticle: 'getArticle',
    addArticleSendRecord: 'addArticleSendRecord',
    starArticle: 'starArticle',
    getOrganizationArticles: 'getOrganizationArticles',
    getMyArticles: 'getMyArticles',
    getMyTeamArticles: 'getMyTeamArticles',
    getSourceCorpArticles: 'getSourceCorpArticles',
    searchCorpArticles: 'searchCorpArticles',
  },

  survery: {
    getSurveyCateList: 'getSurveryCateList',
    getSurveyList: 'getList',
    createSurveyRecord: 'createRecord',
    getSurveyDetail: 'getDetail',
    getAnswer: 'getAnswer'

  },
  member: {
    addCustomer: 'add',
    updateCustomer: 'update',
    transferCustomers: 'transferCustomers',
    doctorCreatedTeamsCustomerLimitation: 'doctorCreatedTeamsCustomerLimitation',
    getGroups: 'getGroups',
    createGroup: 'createGroup',
    updateGroup: 'updateGroup',
    removeGroup: 'removeGroup',
    sortGroups: 'sortGroups',
    addGroupIdForMember: 'addGroupIdForMember',
    bindMiniAppArchive: "bindMiniAppArchive",
    getCustomerByCustomerId: 'getCustomerByCustomerId',
    getMiniAppCustomers: 'getMiniAppCustomers',
    getTeamCustomers: 'getTeamCustomers',
    getUnbindMiniAppCustomers: 'getUnbindMiniAppCustomers',
    searchCorpCustomer: 'searchCorpCustomer',
    searchCorpCustomerWithFollowTime: 'searchCorpCustomerWithFollowTime',
    searchCorpCustomerForCaseList: 'searchCorpCustomerForCaseList', // 档案列表专用接口
    unbindMiniAppArchive: 'unbindMiniAppArchive',
    // 健康档案相关接口
    addMedicalRecord: 'addMedicalRecord',
    getMedicalRecordById: 'getMedicalRecordById',
    updateMedicalRecord: 'updateMedicalRecord',
    removeMedicalRecord: 'removeMedicalRecord',
    getCustomerMedicalRecord: 'getCustomerMedicalRecord',
    // 客户阶段
    getCustomerType: 'getCustomerType',
  },
  wecom: {
    addContactWay: 'addContactWay'
  },
  im: {
    getUserSig: 'getUserSig',
    sendSystemMessage: "sendSystemMessage",
    getChatRecordsByGroupId: "getChatRecordsByGroupId",
    sendConsultRejectedMessage: "sendConsultRejectedMessage",
    endConsultation: "endConsultation",
    openConsultation: "openConsultation",
    getGroupListByGroupId: "getGroupListByGroupId",
    acceptConsultation: "acceptConsultation",
    sendArticleMessage: "sendArticleMessage",
    getChatRecordsByGroupId: "getChatRecordsByGroupId",
    getGroupList: "getGroupList",
    followUpInquiry: "followUpInquiry",
    supplementMedicalCase: "supplementMedicalCase",
    rejectConsultation: "rejectConsultation",
    saveConversationSubscribeResult: "saveConversationSubscribeResult",
    sendConversationSubscribeEvent: "sendConversationSubscribeEvent"
  },
  todo: {
    getCustomerTodos: 'getCustomerTodos',
    getTodoById: 'getTodoById',
    setTodoStatus: 'setTodoStatus',
    updateTaskTodoResult: 'updateTaskTodoResult',
    updateEvent: 'updateEvent',
    removeTodo: 'removeTodo',
    createEvents: 'createEvents',
    executeManagementPlanTodo: 'executeManagementPlanTodo',
    getManagementPlan: 'getManagementPlan',
    getManagementPlanById: 'getManagementPlanById',
    getMyManagementPlanTemplateLibrary: 'getMyManagementPlanTemplateLibrary',
    toggleMyFollowupFavorite: 'toggleMyFollowupFavorite',
    getNextFollowUpTime: 'getNextFollowUpTime',
    // 服务记录相关接口
    getServiceRecord: 'getServiceRecord',
    addServiceRecord: 'addServiceRecord',
    updateServiceRecord: 'updateServiceRecord',
    removeServiceRecord: 'removeServiceRecord',
    // 客户流转记录
    customerTransferRecord: 'customerTransferRecord',
    // sendConsultRejectedMessage: "sendConsultRejectedMessage"
    getTeamTodos: 'getTeamTodos',
    updateTaskTodo: 'updateTaskTodo'
  }

}
const urls = Object.keys(urlsConfig).reduce((acc, path) => {
  const config = urlsConfig[path] || {};
  const keys = Object.keys(config);
  keys.forEach((key) => {
    const data = acc[key];
    if (data) {
      throw new Error(`${data[0]}.${data[1]}和${path}.${key}重复了`)
    }
    acc[key] = [path, config[key]]
    return acc
  })
  return acc
}, {})
console.log('urls: ', urls)

export default async function api(urlId, data, loading) {
  const config = urls[urlId];
  if (!config) {
    throw new Error(`Unknown URL ID: ${urlId}`);
  }
  const [path, type] = config;
  return request({
    url: `/getYoucanData/${path}`,
    data: {
      ...data,
      type,
    },
  }, loading)
}

