package com.yfd.monitor.gdw2019.transmit.event.request.impl.message.query.cmd_parent;

import com.yfd.monitor.gdw2019.bean.Device;
import com.yfd.monitor.gdw2019.bean.ParentPlatform;
import com.yfd.monitor.gdw2019.transmit.event.request.SIPRequestProcessorParent;
import com.yfd.monitor.gdw2019.transmit.event.request.impl.message.IMessageHandler;
import com.yfd.monitor.gdw2019.transmit.event.request.impl.message.query.QueryMessageByparentHandler;
import com.yfd.monitor.gdw2019.utils.SipUtils;
import com.yfd.monitor.service.IPlayService;
import com.yfd.monitor.storager.IVideoManagerStorage;
import gov.nist.javax.sip.message.SIPRequest;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sdp.SdpParseException;
import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import java.text.ParseException;

@Component
public class Control_playbackByParentMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler {

    private Logger logger = LoggerFactory.getLogger(Control_playbackByParentMessageHandler.class);
    private final String cmdType = "Control_Playback";

    @Autowired
    private QueryMessageByparentHandler queryMessageHandler;


    @Autowired
    private IVideoManagerStorage storager;

    @Autowired
    private IPlayService playService;

    @Override
    public void afterPropertiesSet() throws Exception {
        queryMessageHandler.addHandler(cmdType, this);
    }

    @Override
    public void handForDevice(RequestEvent evt, Device device, Element element) {

    }

    @Override
    public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) throws InvalidArgumentException, ParseException, SipException, SdpParseException {
        //处理上级系统发出的设备控制指令
        SIPRequest request = (SIPRequest) evt.getRequest();
        String channelId = SipUtils.getChannelIdFromRequest(request);
        String requesterId = SipUtils.getUserIdFromFromHeader(request);
        Device  device = storager.queryVideoDeviceByPlatformIdAndChannelId(requesterId, channelId);
        String contentString = new String(request.getRawContent());

        //playService.pauseRtp(streamId);
        System.out.println("this is test");

    }


}
