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

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.cmp.model.DataCenterBean;
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.DataCenter;
import com.bocloud.ims.interfaces.resource.DataCenterService;

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

/**
 * 数据中心相关接口
 *
 * @author dmw
 */
@Api(value = "数据中心", tags = "数据中心")
@RestController
@RequestMapping("/v1/dcs")
public class DataCenterController {

	@Autowired
	private DataCenterService dataCenterService;

	/**
	 * 获取数据中心列表
	 *
	 * @param pager
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查询数据中心列表",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "数据中心", operation = "获取数据中心列表")
	@GetMapping
	public BocloudResult<GridBean<DataCenter>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return dataCenterService.list(pager, context);
	}

	/**
	 * 添加数据中心
	 *
	 * @param center
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "添加数据中心",  httpMethod = "POST")
	@Log(module = BoCloudService.IMS, target = "数据中心", operation = "添加数据中心")
	@PostMapping
	public BocloudResult<DataCenter> create(@RequestBody DataCenter center, @Value(Common.REQ_CONTEXT) RequestContext context) {
		return dataCenterService.create(center, context.getTarget());
	}

	/**
	 * 修改数据中心
	 *
	 * @param id
	 * @param bean
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "修改数据中心",  httpMethod = "PUT")
	@Log(module = BoCloudService.IMS, target = "数据中心", operation = "修改数据中心")
	@PutMapping("/{id}")
	public BocloudResult<DataCenter> modify(@PathVariable(value = Common.ID) Long id, @RequestBody DataCenterBean bean,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		bean.setId(id);
		return dataCenterService.modify(bean, context.getTarget());
	}

	/**
	 * 移除数据中心
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "移除数据中心",  httpMethod = "DELETE")
	@Log(module = BoCloudService.IMS, target = "数据中心", operation = "移除数据中心")
	@DeleteMapping("/{id}")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return dataCenterService.remove(id, context.getTarget());
	}

	/**
	 * 查看数据中心详细信息
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(tags = { "CMC",
			"CSC" }, value = "查看数据中心详情",  httpMethod = "GET")
	@Log(module = BoCloudService.IMS, target = "数据中心", operation = "查看数据中心详情")
	@GetMapping("/{id}")
	public BocloudResult<DataCenter> detail(@PathVariable(value = Common.ID) Long id) {
		return dataCenterService.detail(id);
	}

}
