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

import com.alibaba.fastjson.JSON;
import com.bocloud.cmp.model.OsHosts;
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.powervc.PowervcHmc;
import com.bocloud.ims.interfaces.resource.powervc.PowervcHmcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * powervc中的hmc连接
 * 
 * @author luyanchao
 * @since 2019/1/23 14:00
 */
@RestController
@RequestMapping("/v1/powervc")
@Api(value = "Powervc中的HMC连接", tags = "Powervc中的HMC连接")
public class PowervcHmcController {

	private final PowervcHmcService hmcService;

	public PowervcHmcController(PowervcHmcService hmcService) {
		this.hmcService = hmcService;
	}

	/**
	 * 分页查询
	 *
	 *
	 * @param pager
	 *            分页参数
	 * @param context
	 *            操作者信息
	 * @return 数据结果集
	 */
	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "查询")
	@RequestMapping(value = "/hmcs", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询",  httpMethod = "GET")
	public BocloudResult<GridBean<PowervcHmc>> list(Pager pager) {
		return hmcService.list(pager);
	}

	/**
	 * 创建
	 *
	 * @param params
	 *            参数信息
	 * @param context
	 *            操作者信息
	 * @return 空
	 */
	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "创建")
	@RequestMapping(value = "/hmcs", method = { RequestMethod.POST })
	@ApiOperation(tags={"CMC","CSC"},value = "创建",  httpMethod = "POST")
	public BocloudResult<PowervcHmc> create(@RequestParam(value = Common.PARAMS) String params,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		long vendorId = JSON.parseObject(params).getLongValue("vendorId");
		PowervcHmc hmc = JSON.parseObject(params, PowervcHmc.class);
		return hmcService.create(vendorId, hmc, context,null);
	}

	/**
	 * 修改
	 *
	 * @param params
	 *            参数信息
	 * @param context
	 *            操作者信息
	 * @return 空
	 */
	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "修改")
	@RequestMapping(value = "/hmcs/{id}", method = { RequestMethod.PUT })
	@ApiOperation(tags={"CMC","CSC"},value = "修改",  httpMethod = "PUT")
	public BocloudResult<PowervcHmc> modify(@PathVariable(value = Common.ID) long id,
			@RequestParam(value = Common.PARAMS) String params, @Value(Common.REQ_CONTEXT) RequestContext context) {
		PowervcHmc hmc = JSON.parseObject(params, PowervcHmc.class);
		return hmcService.modify(id, hmc, context, null);
	}

	/**
	 * 删除
	 *
	 * @param id
	 *            参数信息
	 * @param context
	 *            操作者信息
	 * @return 空
	 */
	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "删除")
	@RequestMapping(value = "/hmcs/{id}", method = { RequestMethod.DELETE })
	@ApiOperation(tags={"CMC","CSC"},value = "删除",  httpMethod = "DELETE")
	public BocloudResult<PowervcHmc> remove(@PathVariable(value = Common.ID) long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcService.remove(id, context, null);
	}

	/**
	 * 详情
	 *
	 * @param id
	 *            参数信息
	 * @param context
	 *            操作者信息
	 * @return 空
	 */
	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "详情")
	@RequestMapping(value = "hmcs/{id}", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "详情",  httpMethod = "GET")
	public BocloudResult<PowervcHmc> detail(@PathVariable(value = Common.ID) long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcService.detail(id, context);
	}

	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "按主机查询HMC连接")
	@RequestMapping(value = "/hosts/{id}/hmcs", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "按主机查询HMC连接",  httpMethod = "GET")
	public BocloudResult<List<PowervcHmc>> listByHost(@PathVariable(value = Common.ID) long id) {
		return hmcService.listByHost(id);
	}

	@Log(module = BoCloudService.IMS, target = "Powervc中的HMC连接", operation = "查询HMC连接下所有的主机")
	@RequestMapping(value = "/hmcs/{id}/hosts", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询HMC连接下所有的主机",  httpMethod = "GET")
	public BocloudResult<OsHosts> listHost(@PathVariable(value = Common.ID) long id) {
		return hmcService.listHost(id);
	}

}
