package iot.lidee.sip.service.impl;

import iot.lidee.sip.domain.SipDevice;
import iot.lidee.sip.enums.Direct;
import iot.lidee.sip.server.MessageInvoker;
import iot.lidee.sip.server.msg.DeviceControl;
import iot.lidee.sip.service.IPtzCmdService;
import iot.lidee.sip.service.ISipDeviceService;
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 ISipDeviceService sipDeviceService;

    public boolean directPtzCmd(String deviceId, String channelId, Direct direct, Integer speed) {
        Map<Direct, Integer> directAndSpeed = new HashMap<>();
        directAndSpeed.put(direct, speed);
        SipDevice 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;
    }

}
