package com.yfd.monitor.vmanager.gdw2019.stationnode;


import com.yfd.monitor.conf.exception.ControllerException;
import com.yfd.monitor.gdw2019.bean.SubstationNode;
import com.yfd.monitor.gdw2019.transmit.cmd.impl.SIPCommanderFroNode;
import com.yfd.monitor.vmanager.bean.ErrorCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.text.ParseException;

@Tag(name  = "边缘节点控制")

@RestController
@RequestMapping("/api/stationnode")
public class StationNodeController {

	private final static Logger logger = LoggerFactory.getLogger(StationNodeController.class);

	@Autowired
	private SIPCommanderFroNode cmder;

    @Resource
    private SubstationNode substationNode;

	/***
	 * 向边缘节点下发巡视任务
	 * @param stationcode 变电站编号
	 * @param taskid 巡视任务ID
	 */
	@Operation(summary = "下发巡视任务")
	@Parameter(name = "stationcode", description = "变电站编号", required = true)
    @Parameter(name = "taskid", description = "巡视任务ID", required = true)
	@PostMapping("/sendTaskToNode")
	public void sendTaskToNode(String stationcode,String taskid){
        substationNode.setStationCode("0001");
        substationNode.setStationGBId("34020000002010000001");
        substationNode.setStationIp("192.168.1.13");
        substationNode.setStationGBPort("5063");
        substationNode.setTransport("TCP");
		try {
			cmder.sendTaskToNode(substationNode);
		} catch (SipException | InvalidArgumentException | ParseException e) {
			logger.error("[命令发送失败] 云台控制: {}", e.getMessage());
			throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
		}
	}



}
