import request from '../js/request'

// 获取设备
export function getDeviceList(params) {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/queryEquipmentByProject',
        method: 'post',
        data: params,
    })
}

/**
 * 设备统计
 * @param {*} id  工程id
 * @returns
 */
const date = new Date()
const year = date.getFullYear() // 年份 4 位
const month = (date.getMonth() + 1).toString().padStart(2, '0') // 月份自动补 0
const currentYearMonth = `${year}-${month}`
export function getDevCount(id) {
    return request({
        url: '/cs-device-boot/deviceUser/devCount',
        method: 'post',
        data: { id: id, time: currentYearMonth },
    })
}

//  获取直连设备模板信息
export function getModel(nDid) {
    return request({
        url: '/access-boot/device/model',
        method: 'post',
        data: {
            nDid,
        },
    })
}

// 直连设备接入
export function addDevice(params) {
    return request({
        url: '/access-boot/device/access',
        method: 'post',
        header: {
            'Content-Type': 'application/json',
        },
        data: params,
    })
}

// 直连设备注册
export function registerDevice(nDid, type) {
    return request({
        url: '/access-boot/device/register',
        method: 'post',
        data: {
            nDid,
            type,
        },
    })
}

// 查询拓扑图模板
export const getTopoTemplate = () => {
    return request({
        url: '/cs-device-boot/topologyTemplate/queryImage',
        method: 'POST',
    })
}

// 查询拓扑图模板监测点
export const queryByTopoId = (id) => {
    return request({
        url: '/cs-device-boot/lineTemplate/queryByTopoId',
        method: 'POST',
        data: {
            topoId: id,
        },
    })
}
// 查询设备拓扑图
export const queryTopologyDiagram = (devId) => {
    return request({
        url: '/cs-device-boot/lineTopologyDiagram/queryTopologyDiagram',
        method: 'POST',
        data: {
            devId,
        },
    })
}

// 设备扫码移交

export const transferDevice = (id, userId) => {
    return request({
        url: '/cs-device-boot/deviceUser/transfer',
        method: 'POST',
        data: {
            ids: id,
            userId: userId || uni.getStorageSync('userInfo').userIndex,
        },
    })
}
// 设备扫码分享

export const shareDevice = (id, userId) => {
    return request({
        url: '/cs-device-boot/deviceUser/share',
        method: 'POST',
        data: {
            ids: id,
        },
    })
}

// 设备删除

export const deleteDevice = (id) => {
    return request({
        url: '/cs-device-boot/deviceUser/delete',
        method: 'POST',
        data: {
            eid: id,
        },
    })
}

// 设备查询通过id获取
export const queryDeivceById = (id) => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/queryEquipmentById',
        method: 'POST',
        data: {
            ids: id,
        },
    })
}

// 字典树接口通过id
export const queryByid = (id) => {
    return request({
        url: '/system-boot/dictTree/queryByid',
        method: 'post',
        data: {
            id,
        },
    })
}

//设备修改监测点信息
export const updateDevice = (params) => {
    return request({
        url: '/cs-device-boot/lineTopologyDiagram/auditList',
        method: 'POST',
        header: {
            'Content-Type': 'application/json',
        },
        data: params,
    })
}

// 设备用户列表
export const queryDeviceUser = (devId) => {
    return request({
        url: '/cs-device-boot/deviceUser/queryUserById',
        method: 'POST',
        data: {
            devId,
        },
    })
}

// 取消分享
export const cancelShare = (params) => {
    return request({
        url: '/cs-device-boot/deviceUser/cancelShare',
        method: 'POST',
        data: params,
    })
}

// 取消调试
export const cancelDebug = (params) => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/deleteTest',
        method: 'POST',
        data: params,
    })
}

// 完成调试
export const finishDebug = (params) => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/testcompletion',
        method: 'POST',
        data: params,
    })
}
// 置顶设备、工程
export const engineeringPinToTop = (params) => {
    return request({
        url: '/cs-device-boot/csUserPins/engineeringPinToTop',
        method: 'POST',
        data: params,
        header: {
            'Content-Type': 'application/json',
        },
    })
}
// 查询工程树
export const lineTree = (params) => {
    return request({
        url: '/cs-device-boot/csLedger/AppLineTree',
        method: 'POST',
        // data: {
        //     type: 'engineering',
        // },
        // header: {
        //     'Content-Type': 'application/json',
        // },
    })
}
// 查询工程
export const queryEngineeringPage = (params) => {
    return request({
        url: '/cs-device-boot/engineering/queryEngineeringPage',
        method: 'POST',
        data: params,
        header: {
            'Content-Type': 'application/json',
        },
    })
}
// 通过ndid查询出厂设备
export const queryEquipmentByndid = (params) => {
    return request({
        url: '/cs-device-boot/EquipmentDelivery/queryEquipmentByndid',
        method: 'POST',
        data: params,
    })
}
