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

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.ims.entity.resource.QosPolicy;
import com.bocloud.ims.interfaces.resource.QosPolicyService;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/qos/policys")
@Api(value = "QoS管理", tags = "QoS管理")
public class QosPolicyController {

	@Autowired
	private QosPolicyService qosPolicyService;

	/**
	 * 查询QoS列表
	 *
	 * @param pager
	 * @param condition
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "QoS列表查询",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "查询QoS列表")
	@GetMapping
	public BocloudResult<GridBean<QosPolicy>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return qosPolicyService.list(pager, context);
	}

	/**
	 * 查询QoS列表
	 *
	 * @param pager
	 * @param condition
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "通过condition方式查询QoS列表",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "查询QoS列表")
	@GetMapping("/condition")
	public BocloudResult<List<QosPolicy>> condition(@RequestParam(value = Common.CONDITION, required = false) String condition,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return qosPolicyService.condition(condition, context);
	}

	/**
	 * 保存qos
	 *
	 * @param qosPolicy
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "保存QoS",  httpMethod = "POST")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "保存QoS Policy")
	@PostMapping
	public BocloudResult<String> create(@RequestBody QosPolicy qosPolicy, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return qosPolicyService.create(qosPolicy, context);
	}

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

	/**
	 * 批量删除堆栈
	 *
	 * @return 操作结果
	 * @throws Exception
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "批量删除",  httpMethod = "DELETE")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "删除QoS")
	@DeleteMapping
	public BocloudResult<String> batchRemove(@RequestBody List<Long> idArray,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return qosPolicyService.batchRemove(idArray, context);
	}

	/**
	 * 更新QoSPolicy
	 *
	 * @param id
	 * @param qosPolicy
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "更新QoS",  httpMethod = "PUT")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "更新QoS")
	@PutMapping(value = "/{id}")
	public BocloudResult<String> modify(@PathVariable(value = Common.ID) Long id, @RequestBody QosPolicy qosPolicy,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return qosPolicyService.modify(qosPolicy, context.getTarget());
	}

	/**
	 * 查询QoSPolicy详情
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询QoS详情",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "QoS管理", operation = "查询QoS详情")
	@GetMapping(value = "/{id}")
	public BocloudResult<QosPolicy> detail(@PathVariable(value = Common.ID) Long id) {
		return qosPolicyService.detail(id);
	}

}
