import request from '../utils/request';
import { TLogin, TAccount, IpagingRes, TDevice, TOrg, TRoleList, TStatisticsDevice, statisticsContentReq, statisticsContentRes, TStatisticsCount, TWarnRecord, TWarningDetail, TWarningConfirm, TDeviceConfigModify, TDeviceConfig, THealthLatestData, TLocateRecord, TSetUseStatus, TRoleMenuList, TRoleModify, TbindWeb, TstatisticsUseCount } from "./index.d";

export const fetchLogin = (p: TLogin.Ireq): Promise<TLogin.IRes> => {
  return request({
    url: '/v1/api/login',
    method: 'post',
    data: p
  });
};

// 批量导入账号样例
export const exportDemoAccount = (): Promise<any> => {
  return request({
    url: '/v1/api/upload/exportDemo/account',
    method: 'get',
    responseType: 'blob'
  });
};


export const fetchData = () => {
  return request({
    url: './mock/table.json',
    method: 'get'
  });
};


export const fetchUserData = () => {
  return request({
    url: './mock/user.json',
    method: 'get'
  });
};

export const fetchRoleData = () => {
  return request({
    url: './mock/role.json',
    method: 'get'
  });
};


// -------------------------------------------------------------------------------------------------------------------

// 添加用户
export const accountAdd = (p: TAccount.IAdd): Promise<null> => {
  return request({
    url: '/v1/api/account/add',
    method: 'post',
    data: p
  });
};
// 删除用户
export const accountDeletet = (p: TAccount.Idel): Promise<null> => {
  return request({
    url: '/v1/api/account/delete',
    method: 'post',
    data: p
  });
};
// 修改用户
export const accountModify = (p: TAccount.IAdd): Promise<null> => {
  return request({
    url: '/v1/api/account/modify',
    method: 'post',
    data: p
  });
};
// 获取用户列表
export const accountList = (p: TAccount.IListReq): Promise<IpagingRes<TAccount.IListRes>> => {
  return request({
    url: '/v1/api/account/list',
    method: 'get',
    params: p
  });
};
// 获取组织下账号列表
export const accountListOrg = (orgId: number): Promise<TAccount.IListRes[]> => {
  return request({
    url: '/v1/api/account/list/org',
    method: 'get',
    params: { orgId }
  });
};
// 重置密码
export const passwordReset = (p: TAccount.IResetPwd): Promise<null> => {
  return request({
    url: '/v1/api/account/password/reset',
    method: 'post',
    data: p
  });
};


// 获取设备列表
export const deviceList = (p: TDevice.IListReq): Promise<IpagingRes<TDevice.IListRes>> => {
  return request({
    url: '/v1/api/device/list',
    method: 'get',
    params: p
  });
};

// 设置监测模式
export const setMonitor = (p: TDevice.ISetMonitor): Promise<null> => {
  return request({
    url: '/v1/api/device/set/monitor',
    method: 'post',
    data: p
  });
};

// 设置模式
export const setMode = (p: TDevice.ISetMonitor): Promise<null> => {
  return request({
    url: '/v1/api/device/set/mode',
    method: 'post',
    data: p
  });
};

// 获取定位
export const deviceGetLocation = (p: TDevice.ISetMonitor): Promise<null> => {
  return request({
    url: '/v1/api/device/getLocate',
    method: 'post',
    data: p
  });
};

// 设备控制
export const deviceControl = (p: TDevice.ISetMonitor): Promise<null> => {
  return request({
    url: '/v1/api/device/control',
    method: 'post',
    data: p
  });
};

// 设备使用记录
export const deviceUseRecord = (p: TDevice.IRecordReq): Promise<IpagingRes<TDevice.IUseRecordRes>> => {
  return request({
    url: '/v1/api/device/use/record',
    method: 'get',
    params: p
  });
};

// 预警记录
export const warningRecord = (p: TDevice.IRecordReq): Promise<IpagingRes<TDevice.IWarningRecordRes>> => {
  return request({
    url: '/v1/api/warning/record',
    method: 'get',
    params: p
  });
};

// 新增机构
export const orgAdd = (p: TOrg.IAdd): Promise<null> => {
  return request({
    url: '/v1/api/org/add',
    method: 'post',
    data: p
  });
};
// 修改机构
export const orgModify = (p: TOrg.IAdd): Promise<null> => {
  return request({
    url: '/v1/api/org/modify',
    method: 'post',
    data: p
  });
};
// 机构列表
export const orgList = (p?: TOrg.IListReq): Promise<IpagingRes<TOrg.IOrgRecordRes>> => {
  return request({
    url: '/v1/api/org/page',
    method: 'get',
    params: p
  });
};
// 机构列表
export const orgAllList = (): Promise<TOrg.IOrgRecordRes[]> => {
  return request({
    url: '/v1/api/org/list',
    method: 'get',
  });
};

// 删除机构
export const orgDelete = (p?: TOrg.Idel): Promise<null> => {
  return request({
    url: '/v1/api/org/delete',
    method: 'post',
    data: p
  });
};

// web设备绑定管理员
export const bindWeb = (p: TbindWeb): Promise<null> => {
  return request({
    url: '/v1/api/device/web/bind/web',
    method: 'post',
    data: p
  });
};

// 获取角色列表
export const roleList = (): Promise<TRoleList[]> => {
  return request({
    url: '/v1/api/role/list',
    method: 'get',
  });
};

// 修改角色信息
export const roleModify = (p: TRoleModify.Ireq): Promise<null> => {
  return request({
    url: '/v1/api/role/modify',
    method: 'post',
    data: p
  });
};

// 添加角色信息
export const roleAdd = (p: TRoleModify.Ireq): Promise<null> => {
  return request({
    url: '/v1/api/role/add',
    method: 'post',
    data: p
  });
};

// 设备在线统计
export const statisticsDevice = (): Promise<TStatisticsDevice> => {
  return request({
    url: '/v1/api/statistics/device',
    method: 'get',
  });
};

// 内容数据
export const statisticsContent = (p: statisticsContentReq): Promise<statisticsContentRes> => {
  return request({
    url: '/v1/api/statistics/content',
    method: 'post',
    data: p
  });
};

// 获取统计数据
export const statisticsCount = (): Promise<TStatisticsCount> => {
  return request({
    url: '/v1/api/statistics/count',
    method: 'get',
  });
};

// 告警统计
export const statisticsWarningapi = (): Promise<statisticsContentRes> => {
  return request({
    url: '/v1/api/statistics/warning',
    method: 'get',
  });
};

// 预警记录
export const warnRecord = (p: TWarnRecord.IListReq): Promise<IpagingRes<TWarnRecord.IListRes>> => {
  return request({
    url: '/v1/api/warning/record',
    method: 'get',
    params: p
  });
};

// 获取设备使用数量
export const statisticsUseCount = (): Promise<TstatisticsUseCount> => {
  return request({
    url: '/v1/api/statistics/useCount',
    method: 'get',
  });
};

// 预警记录
export const warningDetail = (p: TWarningDetail.TParams): Promise<TWarningDetail.TRes> => {
  return request({
    url: '/v1/api/warning/detail',
    method: 'get',
    params: p
  });
};

// 预警记录
export const warningConfirm = (p: TWarningConfirm): Promise<null> => {
  return request({
    url: '/v1/api/warning/confirm',
    method: 'post',
    data: p
  });
};

// 获取专项配置
export const deviceConfig = (p: TDeviceConfig.Treq): Promise<TDeviceConfig.Tres> => {
  return request({
    url: '/v1/api/device/deviceConfig',
    method: 'get',
    params: p
  });
};

// 修改专项配置
export const deviceConfigModify = (p: TDeviceConfigModify): Promise<null> => {
  return request({
    url: '/v1/api/device/deviceConfig/modify',
    method: 'post',
    data: p
  });
};

// 获取最新健康数据
export const healthLatestData = (p: THealthLatestData.TReq): Promise<THealthLatestData.TRes> => {
  return request({
    url: '/v1/api/health/latestData',
    method: 'get',
    params: p
  });
};

// 设备定位记录
export const locateRecord = (p: TLocateRecord.TReq): Promise<TLocateRecord.TRes[]> => {
  return request({
    url: '/v1/api/device/locate/record',
    method: 'get',
    params: p
  });
};

// 设置使用状态
export const setUseStatus = (p: TSetUseStatus.TReq): Promise<null> => {
  return request({
    url: '/v1/api/device/set/useStatus',
    method: 'post',
    data: p
  });
};

// 设置禁用状态
export const setStatus = (p: TSetUseStatus.TReq): Promise<null> => {
  return request({
    url: '/v1/api/device/set/status',
    method: 'post',
    data: p
  });
};

// 获取菜单列表
export const roleMenuList = (): Promise<TRoleMenuList.TRes[]> => {
  return request({
    url: '/v1/api/role/menu/list',
    method: 'get',
  });
};


