package cn.iocoder.yudao.module.pms.service.yanfan.ptz;

import cn.iocoder.yudao.module.pms.controller.admin.yanfan.enums.Direct;
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.sip.device.YfSipDeviceDO;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.MessageInvoker;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.device.YfSipDeviceService;
import cn.iocoder.yudao.module.pms.service.yanfan.sip.msg.DeviceControl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Slf4j
@Service
public class PtzCmdServiceImpl implements IPtzCmdService {

    @Autowired
    private MessageInvoker messageInvoker;

    @Autowired
    private YfSipDeviceService sipDeviceService;


    public boolean directPtzCmd(String deviceId, String channelId, Direct direct, Integer speed) {
        Map<Direct, Integer> directAndSpeed = new HashMap<>();
        directAndSpeed.put(direct, speed);
        YfSipDeviceDO dev = sipDeviceService.selectSipDeviceBySipId(deviceId);
        if (dev != null) {
            DeviceControl control = new DeviceControl();
            control.setPtzDirect(directAndSpeed);
            control.setDeviceId(channelId);
            messageInvoker.deviceControl(dev, control);
            return true;
        }
        return false;
    }

}
