/**
 * 项目：手机摄像头自动测试化平台
 * @Author: xiongwei
 * @Date: 2022-05-31 09:42:00
 */

import { defHttp } from '/@/utils/http/axios';
import { ApiResponse } from '../model/baseModel';
import {
  LabDevice,
  LabDeviceParams,
  LabDevicePageResult,
  LabDevicePageResponse,
  LabDeviceResponse,
} from '../model/labDevice';

const baseApi = '/v1/device/lab-device';

/**
 * 新增
 */
export const add = (entity: LabDevice) =>
  defHttp.post<LabDevice>({ url: `${baseApi}/`, data: entity });

/**
 * 更新
 */
export const update = (entity: LabDevice) =>
  defHttp.put<LabDevice>({ url: `${baseApi}/`, data: entity });

/**
 * 删除
 */
export const remove = (id: any) =>
  defHttp.delete<Number>({ url: `${baseApi}/${id}` });

/**
 * 分页查询
 */
export const search = (params?: LabDeviceParams) =>
  defHttp.get<LabDevicePageResult>({ url: `${baseApi}/search`, params });

/**
 * 列表查询
 */
export const all = (params?: LabDeviceParams) =>
  defHttp.get<LabDevicePageResult>({ url: `${baseApi}/all`, params });

/**
 * 通过主键查询
 */
export const getById = (id: any) =>
  defHttp.get<LabDevice>({ url: `${baseApi}/${id}` });

/**
 * 单个查询
 */
export const getOne = (params?: LabDeviceParams) =>
  defHttp.get<LabDevice>({ url: `${baseApi}/one`, params });

/**
 * 批量删除
 */
export const batchRemove = (idList: Array<any>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-delete`, data: idList });

/**
 * 批量新增
 */
export const batchAdd = (entityList: Array<LabDevice>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-save`, data: entityList });

/**
 * 批量更新
 */
export const batchUpdate = (entityList: Array<LabDevice>) =>
  defHttp.post<boolean>({ url: `${baseApi}/batch-update`, data: entityList });

/**
 * 查询数量
 */
export const count = (params?: LabDeviceParams) =>
  defHttp.get<Number>({ url: `${baseApi}/count`, params });

/**
 * 查询设备的属性key
 */
export const getAttributesKey = (id: any, params?: any) =>
  defHttp.get({ url: `${baseApi}/${id}/keys/attributes`, params });

/**
 * 查询设备的时序数据key
 */
export const getTimeseriesKey = (id: any) =>
  defHttp.get({ url: `${baseApi}/${id}/keys/timeseries` });

/**
 * 远程调用设备接口rpc(单向)
 */
export const onewayRpc = (id: any, data?: any) =>
  defHttp.post({ url: `${baseApi}/${id}/rpc/oneway`, data });

/**
* 远程调用设备接口rpc(双向)
*/
export const twowayRpc = (id: any, data?: any) =>
  defHttp.post({ url: `${baseApi}/${id}/rpc/twoway`, data });

/**
* 查询设备的属性value
*/
export const getAttributesValue = (id: any, params?: any) =>
  defHttp.get({ url: `${baseApi}/${id}/values/attributes`, params });

/**
 * 查询设备的时序数据value
 */
export const getTimeseriesValue = (id: any, params?: any) =>
  defHttp.get({ url: `${baseApi}/${id}/values/timeseries`, params });

/**
 * 查询设备的最新时序数据value
 */
export const getLatestTimeseries = (id: any, params?: any) =>
  defHttp.get({ url: `${baseApi}/${id}/values/timeseries/latest`, params });

/**
 * 列出复合机器人上连接的测试设备
 */
export const getTestDevices = (id: any) =>
  defHttp.get({ url: `${baseApi}/${id}/list-devices` });
