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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
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.JSONTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.resource.kubernetes.KubeDaemonSet;
import com.bocloud.ims.interfaces.resource.kubernetes.KubeDaemonsetService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/v1/kubernetes/daemonsets")
@Api(value = "Daemonset管理", tags = "Daemonset管理")
public class KubeDaemonSetController {

	@Autowired
	private KubeDaemonsetService kubeDaemonsetService;

	/**
	 * 列表
	 * 
	 * @param page   当前页码
	 * @param rows   页面数据大小
	 * @param params 查询参数，例如：[{"param":{"name":"aaa","password":"1245"},"sign":
	 *               "EQ|UEQ"},{"param":{"name":"aaa","password":"1245"},"sign":
	 *               "EQ|UEQ"}]
	 * @param sorter 排序参数，例如：{"name":0|1,"password":0|1},0表示增序，1表示降序
	 * @param simple 简单查询标记，只有true和false,为false时返回用户的详细信息，为true时只返回id和name值。
	 * @param user   操作者信息
	 * @return 数据结果集
	 */
	@GetMapping
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "Daemonset列表", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetesdaemonsets", operation = "查看daemonsets列表")
	public BocloudResult list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return kubeDaemonsetService.list(pager, context);
	}

	/**
	 * 添加
	 * 
	 * @param params
	 * @param user
	 * @return 添加结果
	 */
	@PostMapping
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "Daemonset新增", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetesdaemonsets", operation = "添加daemonsets")
	public BocloudResult create(@RequestBody KubeDaemonSet kubeDaemonSet,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != kubeDaemonSet) {
			return kubeDaemonsetService.create(kubeDaemonSet, context);
		}
		return ResultTools.formatErrResult();

	}

	/**
	 * 修改
	 * 
	 * @param params
	 * @param id
	 * @param user
	 * @return
	 */
	@PutMapping(value = "/{id}")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "Daemonset编辑", response = BocloudResult.class, httpMethod = "PUT", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetesdaemonsets", operation = "修改daemonsets")
	public BocloudResult modify(@RequestBody KubeDaemonSet kubeDaemonSet, @PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != kubeDaemonSet) {
			kubeDaemonSet.setId(id);
			return kubeDaemonsetService.modify(kubeDaemonSet, context);
		}
		return ResultTools.formatErrResult();
	}

	/**
	 * 移除
	 * 
	 * @param id
	 * @param user
	 * @return 操作结果
	 */
	@DeleteMapping(value = "/{id}")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "Daemonset删除", response = BocloudResult.class, httpMethod = "DELETE", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetesdaemonsets", operation = "移除daemonsets")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return kubeDaemonsetService.remove(id, context);
	}

	/**
	 * 详细信息
	 * 
	 * @param id
	 * @return 操作结果
	 */
	@GetMapping(value = "/{id}")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "Daemonset详情", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetesdaemonsets", operation = "查看daemonsets详情")
	public BocloudResult detail(@PathVariable(value = Common.ID) Long id) {
		return kubeDaemonsetService.detail(id);
	}

}
