import request from '@/utils/request';
import type {
  EmsActionResponse,
  EmsDetailResponse,
  EmsId,
  EmsIdParam,
  EmsListResponse,
  EmsQuery,
  RecordIotenvInstantReportQuery,
  RecordIotenvInstantVO
} from '../types';

// 查询物联网数据列表
export function listRecordIotenvInstant(query?: EmsQuery): Promise<EmsListResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/list',
    method: 'get',
    params: query
  });
}

// 查询物联网数据详细
export function getRecordIotenvInstant(objid: EmsId): Promise<EmsDetailResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/' + objid,
    method: 'get'
  });
}

// 新增物联网数据
export function addRecordIotenvInstant(data: RecordIotenvInstantVO): Promise<EmsActionResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant',
    method: 'post',
    data: data
  });
}

// 修改物联网数据
export function updateRecordIotenvInstant(data: RecordIotenvInstantVO): Promise<EmsActionResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant',
    method: 'put',
    data: data
  });
}

// 删除物联网数据
export function delRecordIotenvInstant(objid: EmsIdParam): Promise<EmsActionResponse> {
  return request({
    url: '/ems/record/recordIotenvInstant/' + objid,
    method: 'delete'
  });
}

// 查询物联网数据列表
export function getRecordIotenvInstantList(query?: RecordIotenvInstantReportQuery): Promise<EmsListResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/getRecordIotenvInstantList',
    method: 'get',
    params: query
  });
}

// 查询物联网多维报表数据
export function getRecordIotenvInstantReportData(query?: RecordIotenvInstantReportQuery): Promise<EmsListResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/getRecordIotenvInstantList',
    method: 'get',
    params: query
  });
}

// 获取所有设备的最新数据（用于首页展示）
export function getLatestRecords(): Promise<EmsListResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/getLatestRecords',
    method: 'get'
  });
}

// 根据父节点ID获取子设备的最新数据
export function getLatestRecordsByParentId(parentId: EmsId): Promise<EmsListResponse<RecordIotenvInstantVO>> {
  return request({
    url: '/ems/record/recordIotenvInstant/getLatestRecordsByParentId/' + parentId,
    method: 'get'
  });
}
