import { request } from 'umi';
import { projectId } from '@/models/spaceFunc.ts';

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

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) => {
    return request(`/sgadmin/duoduo-service/duoduoenv-service/object/eqp/infocode/set?${commonParams()}`, {
        method: 'POST',
        isNotShowErrorToast: true,
        errorSave: true,
        data: JSON.stringify(params),
        headers: {
            'Content-Type': 'application/json',
        },
    });
}

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



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


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

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


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

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

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