import request from '../js/request'
import config from '../js/config'

export function addAppProject(params, files) {
    if (files.length === 0) {
        return request({
            url: '/cs-device-boot/project/addAppProject',
            method: 'post',
            data: params,
        })
    } else {
        return uni.uploadFile({
            url: config.domain + '/cs-device-boot/project/addAppProject', //仅为示例，非真实的接口地址
            files: files,
            header: {
                Authorization: uni.getStorageSync('access_token'),
            },
            formData: params,
        })
    }
}

// 修改项目
export function updateAppProject(params, files) {
    if (files.length === 0) {
        return request({
            url: '/cs-device-boot/project/auditAppProject',
            method: 'post',
            data: params,
        })
    } else {
        return uni.uploadFile({
            url: config.domain + '/cs-device-boot/project/auditAppProject', //仅为示例，非真实的接口地址
            files: files,
            header: {
                Authorization: uni.getStorageSync('access_token'),
            },
            formData: params,
        })
    }
}

export function getProjectList(params) {
    return request({
        url: '/cs-device-boot/project/queryProject',
        method: 'post',
        data: params,
        header: {
            'Content-Type': 'application/json',
        },
    })
}

// 删除项目
export function deleteProject(id) {
    return request({
        url: '/cs-device-boot/project/auditAppProject',
        method: 'post',
        data: {
            id,
            status: 0,
        },
    })
}

// 查询拓扑图

export function queryTopologyDiagramPage(params) {
    return request({
        url: '/cs-device-boot/topologyDiagram/queryTopologyDiagramPage',
        method: 'post',
        data: Object.assign(
            {
                pageNum: 1,
                pageSize: 999,
                projectId: '',
                searchValue: '',
            },
            params,
        ),
        header: {
            'Content-Type': 'application/json',
        },
    })
}

// 删除拓扑图
export function deleteAppTopologyDiagram(id) {
    return request({
        url: '/cs-device-boot/topologyDiagram/AuditAppTopologyDiagram',
        method: 'post',
        data: {
            id,
            status: 0,
        },
    })
}

// 删除拓扑图
export function checkCanDelete(id) {
    return request({
        url: '/cs-device-boot/topologyDiagram/checkCanDelete',
        method: 'post',
        data: {
            id,
        },
    })
}

// 新增拓扑图

export function addAppTopologyDiagram(params, filePath) {
    return uni.uploadFile({
        url: config.domain + '/cs-device-boot/topologyDiagram/addAppTopologyDiagram', //仅为示例，非真实的接口地址
        filePath,
        name: 'file',
        header: {
            Authorization: uni.getStorageSync('access_token'),
        },
        formData: Object.assign(
            {
                topologyDiagramName: '',
                projectId: '',
            },
            params,
        ),
    })
}
