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.Vpn;
import com.bocloud.ims.interfaces.resource.VpnService;
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/vpns")
@Api(value = "VPN管理", tags = "VPN管理")
public class VpnController {

	@Autowired
	private VpnService vpnService;

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

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

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

	/**
	 * 修改
	 *
	 * @param bean
	 * @param id
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改VPN站点",  httpMethod = "PUT")
	@PutMapping("/{id}")
	public BocloudResult<Vpn> modify(@RequestBody Vpn bean, @PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		bean.setId(id);
		return vpnService.modify(bean, 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 vpnService.remove(id, context);
	}

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