import { baseHttpUtils } from "@/utils/http/baseHttpUtils";
import { customHttpUtils } from '@/utils/http/customHttpUtils'
import ScanUtil from '@/utils/scanUtil'
import storage from '@/utils/storageUtil'
import lstorage from '@/utils/old-adm/localStorage'
 
export default class Relation{
    static http = new baseHttpUtils();

    /**
     * @description: 添加源设备
     * @param {*}
     * @return {*}
     */
    static async addSource(params, fn) {
        const res = await Relation.http.postRequest('/datacenter/mep-system-calc/source/add', params);
        return fn ? fn(res) : res   
    }
    /**
     * @description: 查看源设备
     * @param {*} params
     * @param {*} fn
     * @return {*}
     */    
    static async sourceQuery(params, fn) {
        const res = await Relation.http.postRequest(`/datacenter/mep-system-calc/source/query?calcName=${params.calcName}`, params);
        return fn ? fn(res) : res   
    }

    /**
     * @description:  获取源末端 2
     * @param {*} params
     * @param {*} fn
     * @return {*}
     */    
    static async blockQuery(params, fn) {
        const res = await Relation.http.postRequest(`/datacenter/graphic/connected-block-query`, params);
        return fn ? fn(res) : res   
    }
    /**
     * @description:  获取源末端 3
     * @param {*} params
     * @param {*} fn
     * @return {*}
     */    
     static async blockSource(params, fn) {
        const res = await Relation.http.postRequest(`/datacenter/graphic/replace-connected-block-source`, params);
        return fn ? fn(res) : res   
    }
    /**
     * @description:  建筑下的业务空间
     * @param {*} params
     * @param {*} fn
     * @return {*}
     */    
     static async businessSpaceAll(params) {
        const { relation_type, zone_type, proId } = params;
        let userName = storage.get("user_name");
        let ProjectId = lstorage.get("projectId");
        let objectTypes = zone_type ? "?objectTypes=" + zone_type : ''
        const url = (window as any).__systemConf.baseServiceUrl +  `${ScanUtil.datacenter}/relation-calc/${relation_type}${objectTypes}`
        // const headers = { 'projectId': ProjectId, 'Comming': 'adm', 'Account': userName };
        const customHttp =  new customHttpUtils();
        
        return await customHttp.customRequest(url, {}, proId, 'post');

    }
    /**
     * @description: 管网系统设备分块 1
     * @param {*} params
     * @param {*} fn
     * @return {*}
     */    
    static async calcSpecial(params, fn) {
        const res = await Relation.http.postRequest(`/datacenter/calc_special/sys-block?relationType=${params.relationType}`, params);
        return fn ? fn(res) : res
    }
   /**
    * @description: 查询总览
    * @param {*}
    * @return {*}
    */    
    static async graphic(param, fn) {
        const res = await Relation.http.postRequest(`${ScanUtil.datacenter}/graphic/overview`, param);
        return fn ? fn(res) : res
    }
    /**
    * @description: 查询总览数量
    * @param {*}
    * @return {*}
    */    
     static async graphicNumber(param, fn) {
        const res = await Relation.http.postRequest(`${ScanUtil.datacenter}/graphic/query-count`, param);
        return fn ? fn(res) : res
    }
    /**
    * @description: 管网系统确定流向 4
    * @param {*}
    * @return {*}
    */    
     static async sysDirection(param, fn) {
        let buildId = param.BuildingId ? `BuildingId=${param.BuildingId}&` : ''
        const res = await Relation.http.postRequest(`${ScanUtil.datacenter}/calc_special/sys-direction?BlockId=${param.BlockId}&${buildId}Domain=${param.Domain}&SystemName=${param.SystemName}&isSource=${param.isSource}`, param);
        return fn ? fn(res) : res
    }
}
