import { defHttp } from '/@/utils/http/axios';
import { LoginParams, LoginResultModel, GetUserInfoModel, UserInfoModel, RefreshTokenParams, SmsLoginParams } from './model/userModel';

import type { ErrorMessageMode } from '/#/axios';

enum Api {
  Login = '/zhjc/sys/login',
  MonitorDevices = '/zhjc/monitor/devices',
  MonitorSensors = '/zhjc/monitor/sensors',
  // MonitorSensors = '/zhjc/monitor/deviceSensor/status',
  MonitorChart = '/zhjc/monitor/chart',
  MonitorPoints = '/zhjc/monitor/points',
  DeviceKind = '/zhjc/device/stat/kind',
  MonitorAllPoints = '/monitor/allPoints',
  DeviceSensorOnline = '/zhjc/stat/deviceSensorOnline',
  ligongDeviceSensorOnliness = '/zhjc/stat/sensorOnline',
  DeviceSensor = '/zhjc/monitor/deviceSensor/status',
  videoList = '/zhjc/device/warnvideo/videoPageList',
  mqDeviceDataTop20 = '/zhjc/monitordata/mqttbindata/top20',
  updateElevation = '/zhjc/monitor/device/updateElevation',
  count = '/zhjc/monitordata/mqttbindata/stat',
  ResultCount = '/zhjc/stat/dataStat',
  originCount = '/zhjc/stat/data',
  waterDevice = '/zhjc/yx/hydrology/devices',
  waterDeviceStatus = '/zhjc/yx/hydrology/deviceSensor/status',
  newest = '/zhjc/stat/newest',
}

const locationType = { ligong: true };

/**
 * @description: user login api
 */
export function ligongLoginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.Login,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 更新设备高度
 */
export function updateElevation(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.updateElevation,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取设备在线统计
 */
export function ligongDeviceSensorOnline(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.DeviceSensorOnline,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取设备在线统计
 */
export function ligongDeviceSensorOnliness(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.ligongDeviceSensorOnliness,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取统计
 */
export function ligongResultCount(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.ResultCount,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取统计
 */
export function originCount(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.originCount,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

export function waterDevice(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.waterDevice,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

export function waterDeviceStatus(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.waterDeviceStatus,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

export function newest(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.newest,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取统计
 */
export function ligongCount(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.count,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 设备传感器状态
 */
export function ligongDeviceSensor(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.DeviceSensor,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取设备类型统计
 */
export function ligongDeviceKind(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.DeviceKind,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 获取设备列表
 */
export function ligongGetMonitorDevices(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  params.column = 'online,monitorPointCode,deviceKind';
  params.order = 'desc,desc,desc';
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.MonitorDevices,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取设备列表
 */
export function ligongGetVideoList(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.videoList,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}
/**
 * @description: 监测点管理
 */
export function ligongGetMonitorPoints(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.MonitorPoints,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取传感器列表
 */
export function ligongGetMonitorSensors(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.MonitorSensors,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 获取传感器曲线
 */
export function ligongGetMonitorChart(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      ...locationType,
      url: Api.MonitorChart,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

/**
 * @description: 设备传感器状态
 */
export function ligongMonitorDataTop20(params: LoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.get<LoginResultModel>(
    {
      ...locationType,
      url: Api.mqDeviceDataTop20,
      params,
    },
    {
      errorMessageMode: mode,
      joinPrefix: false,
    }
  );
}

export function getMyInfo() {
  return defHttp.get<UserInfoModel>({ url: Api.GetMyInfo });
}
/**
 * @description: getUserInfo
 */
export function getUserInfo() {
  return defHttp.get<GetUserInfoModel>({ url: Api.GetUserInfo });
}

export function getPermCode() {
  return defHttp.get<string[]>({ url: Api.GetPermCode });
}
export async function SendLoginSmsCode(phoneNumber: string) {
  return await defHttp.post<boolean>({ url: Api.SendLoginSmsCode + phoneNumber });
}

export async function doLogout() {
  await defHttp.post(
    {
      url: Api.Logout,
    },
    {
      joinPrefix: false,
    }
  );
}
export function doRefreshToken(params: RefreshTokenParams) {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.RefreshToken,
      params,
    },
    {
      joinPrefix: false,
    }
  );
}
export function smsCodeLoginApi(params: SmsLoginParams, mode: ErrorMessageMode = 'modal') {
  return defHttp.post<LoginResultModel>(
    {
      url: Api.SmsCodeLogin,
      params,
    },
    {
      errorMessageMode: mode,
    }
  );
}

// 密码重置验证码
export function passwordResetCode(mobile) {
  return defHttp.post({
    url: Api.ResetCode + mobile,
  });
}

// 重置密码
export function forgetPasswordApi(data) {
  return defHttp.post({
    url: Api.ResetPassword + data.phoneNumber,
    data,
  });
}

export const getUserToken = (id: string) => {
  return defHttp.get<Record<'token' | 'refreshToken', string>>({
    url: `/third/login/id/${id}`,
  });
};
