import { BasicPageParams } from './../model/baseModel';
import { defHttp } 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',
}

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,
  });
};
