/** 登录接口 POST /api/login/account */
import { request } from 'umi';
import { projectObj } from '@/config/api';
import UserStorage from '@/config/sagacare/sagacare_user';
function getProjectId() {
  const id = projectObj.projectId;
  return id;
}

function commonParams() {
  var userObj = UserStorage.getInstance();
  const user = userObj.getUser();
  var pubname = 'sgadmin';

  return `openid=${user.id}&pubname=${pubname}&projectId=${getProjectId()}&userId=${
    user.id
  }&userName=${user.name}&userPhone=${user.phone}`;
}

export async function getMapList(body: any, options?: { [key: string]: any }) {
  return request<API.MapInfoRes>(
    `/sgadmin/duoduo-service/setup-service/map/queryMapInfo?${commonParams()}`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      from: 'sagacare',
      ...(options || {}),
      data: body,
    },
  );
}
export async function getBuildingList(body: any, options?: { [key: string]: any }) {
  //debugger;
  return request<API.BuildFloorList>(
    `/sgadmin/duoduo-service/object-service/object/building/query?${commonParams()}`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      from: 'sagacare',
      ...(options || {}),
      data: body,
    },
  );
}
export async function getFloorList(body: any, options?: { [key: string]: any }) {
  // debugger;
  return request<API.BuildFloorList>(
    `/sgadmin/duoduo-service/object-service/object/floor/query?${commonParams()}`,
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      from: 'sagacare',
      ...(options || {}),
      data: body,
    },
  );
}
export async function queryDeviceTimeManage(params: any, options?: { [key: string]: any }) {
  //  '/api3/duoduo-service/setup-service/deviceManage/getDeviceTimeManageData'
  return request<API.DeviceTimeType>(
    `/sgadmin/duoduo-service/setup-service/deviceManage/getDeviceTimeManageData?${commonParams()}`,
    {
      method: 'GET',
      from: 'sagacare',
      params: {
        ...params,
      },
      ...(options || {}),
    },
  );
}

// chart
export async function queryPropertyData(params: any, options?: { [key: string]: any }) {
  return request<API.DeviceTimeType>(
    `/sgadmin/duoduo-service/duoduoenv-service/spaceAdjust/queryPropertyData?${commonParams()}`,
    {
      method: 'GET',
      from: 'sagacare',
      params: params,
      ...(options || {}),
    },
  );
}
// 有人无人
export async function getSpaceAdjustArray(params: any) {
  return request<API.DeviceTimeType>(
    `/sgadmin/duoduo-service/object-service/object/equipment/queryFloorSpaceStatus?projectId=${getProjectId()}&floorId=${
      params.floorId
    }&equipType=bodySensor&booleanInfoCode=isPassengerPass&expireTime=5`,
    {
      from: 'sagacare',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    },
  );
}
export async function queryEnvironmentParam(body: any, otherParam: { [key: string]: any }) {
  //api/duoduo-service/object-service/object/floor/queryParam
  return request<API.EnvironmentParam>(
    `/sgadmin/duoduo-service/object-service/object/floor/queryParam?endTime=${otherParam.endTime}&startTime=${otherParam.startTime}&param=${otherParam.param}`,
    {
      method: 'POST',
      from: 'sagacare',
      headers: {
        'Content-Type': 'application/json',
      },
      data: body,
    },
  );
}

export async function getSeasonType(params: any, options?: { [key: string]: any }) {
  return request<API.EnvironmentParam>(
    `/sgadmin/duoduo-service/custom-service/custom/getSeasonType`,
    {
      method: 'GET',
      from: 'sagacare',
      headers: {
        'Content-Type': 'application/json',
      },
      ...(options || {}),
      params: {
        ...params,
      },
    },
  );
}

export async function queryEquipStatistics(params: any, options?: { [key: string]: any }) {
  ///sgadmin/duoduo-service/object-service/object/equipment/queryEquipStatistics
  return request<API.EnvironmentParam>(
    `/sgadmin/duoduo-service/object-service/object/equipment/queryEquipStatistics`,
    {
      method: 'GET',
      from: 'sagacare',
      headers: {
        'Content-Type': 'application/json',
      },
      ...(options || {}),
      params: {
        ...params,
      },
    },
  );
}

export async function querySpace(body: any, options?: { [key: string]: any }) {
  //
  return request<API.EnvironmentParam>(
    `/sgadmin/duoduo-service/object-service/object/space/query?${commonParams()}`,
    {
      method: 'POST',
      from: 'sagacare',
      headers: {
        'Content-Type': 'application/json',
      },
      ...(options || {}),
      data: body,
    },
  );
}

export async function checkToken(header: any, options?: { [key: string]: any }) {
  return request<API.EnvironmentParam>(`/sgadmin/duoduo-service/setup-service/user/zjCheckToken`, {
    method: 'GET',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
      ...header,
    },
    ...(options || {}),
  });
}
//http://10.100.28.79/sgadmin/sso//auth/zjFreshCheckToken
export async function reFreshCheckToken(header: any, options?: { [key: string]: any }) {
  return request<API.EnvironmentParam>(`/sgadmin/sso/auth/zjFreshCheckToken`, {
    method: 'GET',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
      ...header,
    },
    ...(options || {}),
  });
}

export async function queryProjectId(body: any, options?: { [key: string]: any }) {
  return request<API.EnvironmentParam>(`/sgadmin/duoduo-service/setup-service/pjSet/query`, {
    method: 'POST',
    from: 'sagacare',
    headers: {
      'Content-Type': 'application/json',
    },
    ...(options || {}),
    data: body,
  });
}
// 项目拥有的设备
export async function queryProjectEquipType() {
  return request<API.EnvironmentParam>(
    `/sgadmin/duoduo-service/object-service/object/equipment/queryProjectEquipType?${commonParams()}`,
    {
      from: 'sagacare',
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    },
  );
}

export const getUserInfo = (uid: string) => {
  return request(`/user/${uid}`, {
    method: 'get',
  });
};
