package com.yuchen.saas.park.service.service.impl;

import com.yuchen.saas.park.api.vo.responsevo.ResponseVo;
import com.yuchen.saas.park.service.service.SoundLightService;
import com.yuchen.saas.park.service.iot.IotClientService;
import com.yuchen.saas.park.service.util.iot.client.ResourceUtils;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class SoundLightServiceImpl implements SoundLightService {
    @Autowired
    private IotClientService iotClientService;

    @Override
    public ResponseVo soundLightOpenOrClose(Map<String, Object> body) {
        ResponseVo responseVo = new ResponseVo();
        if(Func.isEmpty(body)) {
            responseVo.setCode("1");
            responseVo.setData("请求参数为空！");
            return responseVo;
        }
        String productKey = String.valueOf(body.get("productKey"));
        String deviceName = String.valueOf(body.get("deviceName"));
        String state = String.valueOf(body.get("state"));

        Map<String, Object> openOrClose = new HashMap<String, Object>();
        openOrClose.put("identify", "1".equals(state)
                ? ResourceUtils.SOUND_LIGHT_OPEN:ResourceUtils.SOUND_LIGHT_CLOSE);
        openOrClose.put("productKey", productKey);
        openOrClose.put("deviceName", deviceName);

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("state", state);

        openOrClose.put("params", params);

        System.out.println("openOrClose:" + openOrClose);
        responseVo = iotClientService.serviceCall(openOrClose);
        return responseVo;
    }
}
