import { request } from 'umi';
import { projectId } from '@/config/api.js';
import UserStorage from '@/config/sagacare/sagacare_user';

// function getProjectId() {
//     //const id = window.localStorage.getItem('localProjectId')
//     const id = projectId
//     return id;
// }

function commonParams({ userId, userName, projectId }) {
    // var userObj = UserStorage.getInstance();
    //  const user = userObj.getUser();
    var pubname = '';
    if (getProjectId() == 'Pj3301100002') {
        pubname = 'sgadmin'
    } else {
        pubname = 'sagacareAndtenantslink'
    }
    return `openid=${userId}&pubname=${pubname}&projectId=${projectId}&userId=${userId}&userName=${userName}`;
}

// function commonParams() {
//     return `openid=9a1ecfbacb6b4f249bf2dd3ec7793ead&pubname=sagacareAndtenantslink&projectId=${getProjectId()}&userName=%E5%AE%89%E5%B0%8F%E9%9C%9E&userPhone=17611228068&userId=9a1ecfbacb6b4f249bf2dd3ec7793ead`;
// }


//窗帘  设置设备
//窗帘  设置设备
export const setEquipeHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/object/eqp/infocode/set?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        },
    });
}

//窗帘 获取设备
export const getObjectDataEqpGroupHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/object/objectDataEqpGroup/query?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        }
    });
}



// 灯的状态
export const getLampHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/light/status/query?${commonParams(userProject)}&spaceId=${params}`, {
        timeout: 1000,
        skipErrorHandler: true,
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
        },
    });
};


// 批量 开关灯
export const setallLampHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/light/onoff/set?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        },
    });
};

// 开关失败时 定时查询灯状态 
export const getStatusHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/light/onoff/setSatus?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        },
    });
};


//  空调 - 调节文案/空调信息
export const getFeedbackDocumentsHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/custom/feedback/documents?${commonParams(userProject)}`, {
        isNotShowErrorToast: true,
        errorSave: true,
        method: 'POST',
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        },
    });
};

//  空调 调节
export const changeAirHttp = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/custom/feedbackCreate/v2?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify({ ...params, projectId: getProjectId() }),
        headers: {
            'Content-Type': 'application/json',
        },
    });
};

// 空间环境质量
export const getSpaceAdjustList = (params, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/space/property?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: params,
        headers: {
            'Content-Type': 'application/json',
        },
    });
}
//  批量空调 调节
export const changeAllAirHttp = (body, userProject) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/custom/feedbackCreate/v2Batch?${commonParams(userProject)}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: body,
        headers: {
            'Content-Type': 'application/json',
        },
    });
};
