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.ims.entity.resource.QosPolicyRules;
import com.bocloud.ims.interfaces.resource.QosPolicyRulesService;
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/rules")
@Api(value = "QoS管理", tags = "QoS管理")
public class QosPolicyRulesController {

	@Autowired
	private QosPolicyRulesService qosPolicyRulesService;

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

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

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

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

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

}
