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.KubePersistentVolume;
import com.bocloud.ims.interfaces.resource.kubernetes.KubePersistentVolumeService;

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

@RestController
@RequestMapping("/v1/kubernetes/pvs")
@Api(value = "PV管理", tags = "PV管理")
public class KubePersistentVolumesController {

	@Autowired
	private KubePersistentVolumeService kubePersistentVolumeService;

	/**
	 * 列表
	 * 
	 * @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
	@Log(module = BoCloudService.IMS, target = "Kubernetes持久化存储卷", operation = "查看持久化存储卷列表")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "PV列表", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
	public BocloudResult list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return kubePersistentVolumeService.list(pager);
	}

	/**
	 * 添加
	 * 
	 * @param params
	 * @param user
	 * @return 添加结果
	 */
	@PostMapping
	@Log(module = BoCloudService.IMS, target = "Kubernetes持久化存储卷", operation = "添加持久化存储卷")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "添加PV", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
	public BocloudResult create(@RequestBody KubePersistentVolume volume,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != volume) {
			return kubePersistentVolumeService.create(volume, context);
		}
		return ResultTools.formatErrResult();

	}

	/**
	 * 修改
	 * 
	 * @param params
	 * @param id
	 * @param user
	 * @return
	 */
	@PutMapping(value = "/{id}")
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改PV", response = BocloudResult.class, httpMethod = "PUT", produces = MediaType.APPLICATION_JSON_VALUE)
	@Log(module = BoCloudService.IMS, target = "Kubernetes持久化存储卷", operation = "修改持久化存储卷")
	public BocloudResult modify(@RequestBody KubePersistentVolume volume, @PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		if (null != volume) {
			return kubePersistentVolumeService.modify(volume, context);
		}
		return ResultTools.formatErrResult();
	}

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

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

}
