package com.yihu.hos.broker.controllers;

import com.yihu.hos.broker.services.camel.ESBCamelService;
import com.yihu.hos.web.framework.model.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lingfeng on 2016/8/4.
 */
@RestController
@RequestMapping("/esb")
public class ESBCamelController {
    @Autowired
    private ESBCamelService esbCamelService;

    @RequestMapping(value = "/heartbeat", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ApiOperation(value = "测试服务器可以正常连接", produces = "application/json", notes = "测试服务器可以正常连接")
    public void heartbeat() {
        System.out.println("test");
    }

    @RequestMapping(value = "/serviceFlow", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ApiOperation(value = "新增流程", produces = "application/json", notes = "当Arbiter通知一个的流程被创建时，该事件被触发")
    public Result onServiceFlowAdd(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowAdd(msg);
    }


    @RequestMapping(value = "/serviceFlow/add", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ApiOperation(value = "修改流程", produces = "application/json", notes = "当Arbiter通知一个的流程被修改（Router，Process被修改或增加）时，该事件被触发")
    public Result onServiceFlowModifyAdd(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowModifyAdd(msg);
    }

    @RequestMapping(value = "/serviceFlow/reduce", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
    @ApiOperation(value = "修改流程", produces = "application/json", notes = "当Arbiter通知一个的流程被修改（Router，Process被删除）时，该事件被触发")
    public Result onServiceFlowModifyReduce(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowModifyReduce(msg);
    }

    @RequestMapping(value = "/serviceFlow", produces = "application/json;charset=UTF-8", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除流程", produces = "application/json", notes = "当Arbiter通知一个的流程被删除时，该事件被触发")
    public Result onServiceFlowDelete(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowDelete(msg);
    }

    @RequestMapping(value = "/serviceFlow/start", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ApiOperation(value = "启动服务流程", produces = "application/json", notes = "启动服务流程时，该事件被触发")
    public Result onServiceFlowStart(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowStart(msg);
    }

    @RequestMapping(value = "/serviceFlow/stop", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
    @ApiOperation(value = "停止服务流程", produces = "application/json", notes = "停止服务流程时，该事件被触发")
    public Result onServiceFlowStop(
            @ApiParam(name = "msg", value = "消息", required = true)
            @RequestBody() String msg) {
        return esbCamelService.onServiceFlowStop(msg);
    }
}
