import type { APIMethod } from '@crami/bui-types';
//通用接口参数处理
import { getInfo, ICP_CONFIG } from '@remote/icpx-platform/utils';
import { computed, reactive } from 'vue';

export const commonApi = () => {
  const commonParams = computed(() => {
    return getInfo(ICP_CONFIG);
  });

  const studioCacheParam = reactive({
    //产品线
    productLine: commonParams.value?.project,
    //语言
    lang: commonParams.value?.lang,
    //视图名称
    //   name: commonParams.value?.listView,
    //行政组
    // userDept: commonParams.value?.userDept,
    // //用户组
    // userGroup: commonParams.value?.userGroup,
    //项目实例
    projectCode: commonParams.value?.projectCode,
    // 多时区
    timeZone: commonParams.value?.TIME_ZONE,
  });
  const systemParam = reactive({
    //   viewName: commonParams.value?.listViewName,
    lang: commonParams.value?.lang,
    //数据库连接
    connect: commonParams.value?.connect,
    //所属租户
    companyId: commonParams.value?.companyId,
    //行政组
    userDept: commonParams.value?.userDept,
    //用户组
    userGroup: commonParams.value?.userGroup,
    projectCode: commonParams.value?.projectCode,
    // 多时区
    timeZone: commonParams.value?.TIME_ZONE,
  });
  const paraList = {
    loadAllStructure: false,
    lang: commonParams.value?.lang,
    connect: commonParams.value?.connect,
    companyId: commonParams.value?.companyId,
    userGroup: commonParams.value?.userGroup,
    projectCode: commonParams.value?.projectCode,
    userDept: commonParams.value?.userDept,
  };
  return {
    studioCache: {
      getMetaInfo: {
        url: '/api/studio-cache/page/getMetaInfo',
        params: studioCacheParam,
        method: 'post' as APIMethod,
      },
      getByProjectAndType: {
        url: '/api/studio-cache/metaData/getByProjectAndType',
        params: {
          productLine: commonParams.value?.project,
          projectCode: commonParams.value?.projectCode,
          timeZone: commonParams.value?.TIME_ZONE,
        },
        method: 'get' as APIMethod,
      },
    },
    system: {
      getData: {
        url: '/api/system/view/getData',
        params: systemParam,
        method: 'post' as APIMethod,
      },
      getGetOnePageGridDataList: {
        url: '/api/system/model/getGetOnePageGridDataList',
        params: {
          ...systemParam,
          objectType: '',
        },
        method: 'post' as APIMethod,
      },
      getGetOnePageGridDataListByTenant: {
        url: '/api/system/tenant/getGetOnePageGridDataList',
        params: {
          ...systemParam,
          objectType: '',
        },
        method: 'post' as APIMethod,
      },
      getSltData: {
        url: '/api/system/model/getSltData',
        params: {
          ...systemParam,
          userId: commonParams.value?.user_id,
        },
        method: 'post' as APIMethod,
      },
      getGetTreeRootDataList: {
        url: '/api/system/model/getGetTreeRootDataList',
        params: {
          ...systemParam,
          paraList: JSON.stringify(paraList),
          type: 'tree',
          loadAllStructure: false,
        },
        method: 'post' as APIMethod,
      },
      getGetTreeChildDataList: {
        url: '/api/system/model/getGetTreeChildDataList',
        params: {
          ...systemParam,
          type: 'treeChildren',
          loadAllStructure: false,
        },
        method: 'post' as APIMethod,
      },
      getObjectDataTestList: {
        url: '/api/system/model/GetObjectDataTestList',
        params: {
          ...systemParam,
          userId: commonParams.value?.user_id,
        },
        method: 'post' as APIMethod,
      },
      saveObjectData: {
        url: '/api/msg/sender/saveOrEditMsgSender',
        params: {
          ...systemParam,
          userId: commonParams.value?.user_id,
        },
        method: 'post' as APIMethod,
      },
    },
  };
};
