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

import com.alibaba.fastjson.JSON;
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.VolumeTemplate;
import com.bocloud.ims.interfaces.resource.VolumeTemplateService;
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/storages/template")
@Api(value = "卷模板", tags = "卷模板")
public class VolumeTemplateController {

	@Autowired
	private VolumeTemplateService volumeTemplateService;

	/**
	 * 分页查询
	 * 
	 * @param pager
	 * @param context
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "卷模板", operation = "查询")
	@RequestMapping(method = { RequestMethod.GET })
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询",  httpMethod = "GET")
	public BocloudResult<GridBean<VolumeTemplate>> list(Pager pager,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return volumeTemplateService.list(pager, context);
	}

	/**
	 * 创建
	 * 
	 * @param template
	 * @param context
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "卷模板", operation = "创建")
	@RequestMapping(method = { RequestMethod.POST })
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "创建",  httpMethod = "POST")
	public BocloudResult<VolumeTemplate> create(@RequestBody VolumeTemplate template,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return volumeTemplateService.create(template, context);
	}

	/**
	 * 修改
	 *
	 * @param params
	 * @param id
	 * @param context
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "卷模板", operation = "修改")
	@RequestMapping(value = "/{id}", method = { RequestMethod.PUT })
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改",  httpMethod = "PUT")
	public BocloudResult<VolumeTemplate> modify(@RequestBody VolumeTemplate template,
			@PathVariable(value = Common.ID) Long id, @Value(Common.REQ_CONTEXT) RequestContext context) {
		template.setId(id);
		return volumeTemplateService.modify(template, context);
	}

	/**
	 * 删除
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "卷模板", operation = "删除")
	@RequestMapping(value = "/{id}", method = { RequestMethod.DELETE })
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "删除",  httpMethod = "DELETE")
	public BocloudResult<String> remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return volumeTemplateService.remove(id, context);
	}

	/**
	 * 详情
	 *
	 * @param id
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "卷模板", operation = "详情")
	@RequestMapping(value = "/{id}", method = { RequestMethod.GET })
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "详情",  httpMethod = "GET")
	public BocloudResult<VolumeTemplate> detail(@PathVariable(value = Common.ID) Long id) {
		return volumeTemplateService.detail(id);
	}

}
