package com.bocloud.ims.booter.controller.resource;

import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.resource.Route;
import com.bocloud.ims.interfaces.resource.RouteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/v1/routetables/routes")
@Api(value = "路由", tags = "路由")
public class RouteController {

	@Autowired
	private RouteService routeService;

	@ApiOperation(tags = { "CMC", "CSC" }, value = "查询路由列表", httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "路由", operation = "查询路由表列")
	@GetMapping
	public BocloudResult<GridBean<Route>> list(Pager pager) {
		return routeService.list(pager);
	}

	@ApiOperation(tags = { "CMC", "CSC" }, value = "创建路由", httpMethod = "POST")
	@Log(module = BoCloudService.IMS, target = "路由", operation = "创建路由")
	@PostMapping
	public BocloudResult<Route> create(@RequestBody Route route, @Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != route) {
			return routeService.create(route, context);
		}
		return ResultTools.formatErrResult();
	}

	@ApiOperation(tags = { "CMC", "CSC" }, value = "删除路由", httpMethod = "DELETE")
	@Log(module = BoCloudService.IMS, target = "路由", operation = "删除路由")
	@DeleteMapping("/{id}")
	public BocloudResult<String> remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return routeService.remove(id, context);
	}

	@ApiOperation(tags = { "CMC", "CSC" }, value = "编辑路由", httpMethod = "DELETE")
	@Log(module = BoCloudService.IMS, target = "路由", operation = "编辑路由")
	@PostMapping("/{id}")
	public BocloudResult<Route> modify(@PathVariable(value = Common.ID) Long id, @RequestBody Route route,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != route) {
			return routeService.modify(route, context);
		}
		return ResultTools.formatErrResult();
	}
}
