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

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.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
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.kubernetes.KubeNodeLabel;
import com.bocloud.ims.interfaces.resource.kubernetes.KubeNodeLabelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * k8s 节点 label
 * 
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/v1/kubernetes/node/labels")
@Api(value = "节点标签管理", tags = "节点标签管理")
public class KubeNodeLabelController {

	@Autowired
	private KubeNodeLabelService kubeNodeLabelService;

	/**
	 * 获取标签列表
	 *
	 * @param pager
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "标签", operation = "获取标签列表")
	@GetMapping
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "节点标签列表", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
	public BocloudResult list(Pager pager) {
		return kubeNodeLabelService.list(pager);
	}

	/**
	 * 添加标签
	 *
	 * @param params
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "标签", operation = "添加标签")
	@PostMapping
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "新增节点标签", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
	public BocloudResult create(@RequestBody KubeNodeLabel label) {
		if (null != label) {
			return kubeNodeLabelService.create(label);
		} else {
			return ResultTools.formatErrResult();
		}
	}

	/**
	 * 修改标签
	 *
	 * @param id
	 * @param params
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "标签", operation = "修改标签")
	@PutMapping("/{id}")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改标签", response = BocloudResult.class, httpMethod = "PUT", produces = MediaType.APPLICATION_JSON_VALUE)
	public BocloudResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody KubeNodeLabel label,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != label) {
			label.setId(id);
			return kubeNodeLabelService.modify(label, context);
		} else {
			return ResultTools.formatErrResult();
		}
	}

	/**
	 * 删除标签
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "删除节点标签", response = BocloudResult.class, httpMethod = "DELETE", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "标签", operation = "删除标签")
	@DeleteMapping("/{id}")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id) {
		return kubeNodeLabelService.remove(id);
	}

	/**
	 * 查看标签详情
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "标签详情", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "标签", operation = "查看标签详情")
	@GetMapping("/{id}")
	public BocloudResult detail(@PathVariable(value = Common.ID) Long id) {
		return kubeNodeLabelService.detail(id);
	}
}