import { BasicPageParams } from './../model/baseModel';
import { defHttp, xldAnalystHttp } from '/@/utils/http/axios';
enum HomeEnum {
  home = '/homepage/left/top',
  TenantExpireTimeList = '/homepage/right/overdue',
  EntitiesQueryFind = '/entitiesQuery/find',
  TrendAPI = '/homepage/left/bottom',
  Top10 = '/homepage/right/top10',
  // 资源访问次数
  GetIServerRequestCountData = '/external-service-center/IServer/getIServerRequestCountData',
  // 资源访问次数月度
  GetIServerRequestMonthCountData = '/external-service-center/IServer/getIServerRequestMonthCountData',
  // 资源访问次数年度
  GetIServerRequestYearCountData = '/external-service-center/IServer/getIServerRequestYearCountData',
  // 分组统计组件资源申请次数
  GetSRResourceGroup = '/datasearch-center/space/getSRResourceGroup',
  // 空间分析统计
  BusinessStatistics = '/BusinessStatistics'

}
// 空间服务支撑访问统计
export const GetIServerRequestCount = () => {
  return defHttp.post({
    url: HomeEnum.GetIServerRequestCountData,
  });
}
// 空间服务支撑访问统计月度
export const GetIServerRequestMonthCount = () => {
  return defHttp.post({
    url: HomeEnum.GetIServerRequestMonthCountData,
  });
}
// 空间服务支撑访问统计年度
export const GetIServerRequestYearCount = () => {
  return defHttp.post({
    url: HomeEnum.GetIServerRequestYearCountData,
  });
}
// 组件资源申请次数
export const GetSRResourceGroup = () => {
  return defHttp.post({
    url: HomeEnum.GetSRResourceGroup,
  });
}
// 空间分析统计次数
export const GetXldAnalysisStatistics = () => {
  return xldAnalystHttp.post({
    url: HomeEnum.BusinessStatistics
  })
}


export const getHomeData = () => {
  return defHttp.get({
    url: HomeEnum.home,
  });
};

// 获取即将过期租户列表
export const getTenantExpireTimeList = (params: BasicPageParams) => {
  return defHttp.get({
    url: HomeEnum.TenantExpireTimeList,
    params,
  });
};

export const getTenantTop10 = () => {
  return defHttp.get<{ name: string; count: number }[]>({
    url: HomeEnum.Top10,
  });
};

// 获取entities实体ID
export const getEntitiesId = () => {
  return defHttp.post(
    {
      url: HomeEnum.EntitiesQueryFind,
      data: {
        entityFilter: {
          type: 'apiUsageState',
          resolveMultiple: false,
        },
        pageLink: {
          pageSize: 1,
          page: 0,
          sortOrder: {
            key: {
              type: 'ENTITY_FIELD',
              key: 'createdTime',
            },
            direction: 'DESC',
          },
        },
        entityFields: [
          {
            type: 'ENTITY_FIELD',
            key: 'name',
          },
          {
            type: 'ENTITY_FIELD',
            key: 'label',
          },
          {
            type: 'ENTITY_FIELD',
            key: 'additionalInfo',
          },
        ],
      },
    },
    {
      joinPrefix: false,
    }
  );
};

interface TrendParamsType {
  startTs: number;
  endTs: number;
  interval: number;
  trend:
    | 'CUSTOMER_TREND'
    | 'TENANT_TREND'
    | 'CUSTOMER_MESSAGE_STATISTICAL'
    | 'CUSTOMER_MESSAGE_STATISTICAL';
}
// 获取租户趋势或者客户趋势数据
export const getTrendData = (params: TrendParamsType) => {
  return defHttp.get({
    url: HomeEnum.TrendAPI,
    params,
  });
};
