import request from '@/utils/request'

// 查询能耗设备列表
export function listEnergyDevices(query) {
    return request({
        url: '/subsystem/energy/devices/list',
        method: 'get',
        params: query
    })
}

// 查询能耗设备详细
export function getEnergyDevice(deviceId) {
    return request({
        url: '/subsystem/energy/devices/' + deviceId,
        method: 'get'
    })
}

// 新增能耗设备
export function addEnergyDevice(data) {
    return request({
        url: '/subsystem/energy/devices',
        method: 'post',
        data: data
    })
}

// 修改能耗设备
export function updateEnergyDevice(data) {
    return request({
        url: '/subsystem/energy/devices',
        method: 'put',
        data: data
    })
}

// 删除能耗设备
export function delEnergyDevice(deviceId) {
    return request({
        url: '/subsystem/energy/devices/' + deviceId,
        method: 'delete'
    })
}

// 导出能耗设备
export function exportEnergyDevice(query) {
    return request({
        url: '/subsystem/energy/devices/export',
        method: 'post',
        params: query
    })
}

// 获取能耗统计数据
export function getEnergyStatistics(query) {
    return request({
        url: '/subsystem/energy/statistics',
        method: 'get',
        params: query
    })
}

// 获取能耗曲线数据
export function getEnergyChart(deviceCode, timeRange) {
    return request({
        url: '/subsystem/energy/chart',
        method: 'get',
        params: {
            deviceCode: deviceCode,
            beginTime: timeRange[0],
            endTime: timeRange[1]
        }
    })
}

// 设备控制
export function controlDevice(data) {
    return request({
        url: '/subsystem/energy/control',
        method: 'post',
        data: data
    })
}

// 获取实时能耗数据
export function getRealTimeEnergyData(deviceCode) {
    return request({
        url: '/subsystem/energy/realtime/' + deviceCode,
        method: 'get'
    })
}

// 查询能耗历史记录
export function getEnergyHistory(query) {
    return request({
        url: '/subsystem/energy/history/list',
        method: 'get',
        params: query
    })
}

// 获取能耗报表
export function getEnergyReport(query) {
    return request({
        url: '/subsystem/energy/report',
        method: 'get',
        params: query
    })
}

// 设置能耗阈值
export function setEnergyThreshold(data) {
    return request({
        url: '/subsystem/energy/threshold',
        method: 'post',
        data: data
    })
}

// 获取能耗告警信息
export function getEnergyAlarms(query) {
    return request({
        url: '/subsystem/energy/alarms/list',
        method: 'get',
        params: query
    })
}

// 处理能耗告警
export function handleEnergyAlarm(alarmId, data) {
    return request({
        url: '/subsystem/energy/alarms/' + alarmId,
        method: 'put',
        data: data
    })
}