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

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.ims.entity.resource.VpnPolicy;
import com.bocloud.ims.interfaces.resource.VpnPolicyService;
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.*;

import java.util.List;

@RestController
@RequestMapping("/v1/vpnpolicies")
@Api(value = "VPN策略管理", tags = "VPN策略管理")
public class VpnPolicyController {

	@Autowired
	private VpnPolicyService vpnPolicyService;

	/**
	 * VPN策略列表
	 * 
	 * @param pager
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询VPN策略列表",  httpMethod = "GET")
	@GetMapping
	public BocloudResult<GridBean<VpnPolicy>> list(Pager pager,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return vpnPolicyService.list(pager, context);
	}

	/**
	 * VPN策略列表 condition方式
	 * 
	 * @param condition
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "通过condition方式查询VPN策略列表",  httpMethod = "GET")
	@GetMapping("/condition")
	public BocloudResult<List<VpnPolicy>> condition(
			@RequestParam(value = Common.CONDITION, required = false) String condition,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return vpnPolicyService.condition(condition, context);
	}

	/**
	 * 创建
	 *
	 * @param params
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "创建VPN策略",  httpMethod = "POST")
	@PostMapping
	public BocloudResult<String> create(@RequestBody VpnPolicy vpnPolicy,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return vpnPolicyService.create(vpnPolicy, context);
	}

	/**
	 * 修改
	 *
	 * @param vpnPolicy
	 * @param id
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改VPN策略",  httpMethod = "PUT")
	@PutMapping("/{id}")
	public BocloudResult<VpnPolicy> modify(@RequestBody VpnPolicy vpnPolicy, @PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		vpnPolicy.setId(id);
		return vpnPolicyService.modify(vpnPolicy, context);
	}

	/**
	 * 删除
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "删除VPN策略",  httpMethod = "DELETE")
	@DeleteMapping("/{id}")
	public BocloudResult<String> remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return vpnPolicyService.remove(id, context);
	}

	/**
	 * 详情
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询VPN策略详情",  httpMethod = "GET")
	@GetMapping("/{id}")
	public BocloudResult<VpnPolicy> detail(@PathVariable(value = Common.ID) Long id) {
		return vpnPolicyService.detail(id);
	}

}
