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

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.hmc.HmcVirtualFibreChannelMapping;
import com.bocloud.ims.entity.resource.hmc.params.HmcVirtualFibreChannelMappingVfcCreateParams;
import com.bocloud.ims.interfaces.resource.hmc.HmcVirtualFibreChannelMappingService;
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.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/hmc")
@Api(value = "HMC虚拟光纤适配器", tags = "HMC虚拟光纤适配器")
public class HmcVirtualFibreChannelMappingController {

	private final HmcVirtualFibreChannelMappingService hmcVirtualFibreChannelMappingService;

	@Autowired
	public HmcVirtualFibreChannelMappingController(
			HmcVirtualFibreChannelMappingService hmcVirtualFibreChannelMappingService) {
		this.hmcVirtualFibreChannelMappingService = hmcVirtualFibreChannelMappingService;
	}

	/**
	 * 创建虚拟光纤通道
	 *
	 * @param
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟光纤适配器", operation = "创建")
	@RequestMapping(value = "/vfcs", method = { RequestMethod.POST })
	@ApiOperation(tags={"CMC","CSC"},value = "创建",  httpMethod = "POST")
	public BocloudResult vfcCreate(@RequestBody HmcVirtualFibreChannelMappingVfcCreateParams params,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		long viosId = params.getViosId();
		Integer viosSlot = params.getViosSlot();
		long partitionId = params.getPartitionId();
		Integer partitionSlot = params.getPartitionSlot();
		long fcId = params.getFcId();
		Boolean viosRequired = params.getViosRequired();
		if (viosRequired == null) {
			viosRequired = false;
		}
		return hmcVirtualFibreChannelMappingService.create(viosId, viosSlot, viosRequired, partitionId, partitionSlot,
				fcId, context);
	}

	/**
	 * 删除虚拟光纤通道
	 *
	 * @param
	 * @return
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟光纤适配器", operation = "删除")
	@RequestMapping(value = "/vfcs/{id}", method = { RequestMethod.DELETE })
	@ApiOperation(tags={"CMC","CSC"},value = "删除",  httpMethod = "DELETE")
	public BocloudResult vfcRemove(@PathVariable(value = Common.ID) long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcVirtualFibreChannelMappingService.remove(id, context);
	}

	/**
	 * 查询vfc映射列表
	 *
	 * @param pager
	 *            分页参数
	 * @return 查询结果集
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟光纤适配器", operation = "查询")
	@RequestMapping(value = "/vfcs", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询",  httpMethod = "GET")
	public BocloudResult<GridBean<HmcVirtualFibreChannelMapping>> vfcList(Pager pager) {
		return hmcVirtualFibreChannelMappingService.list(pager);
	}

	@Log(module = BoCloudService.IMS, target = "HMC虚拟光纤适配器", operation = "查询")
	@RequestMapping(value = "/vios/{id}/vfcs", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询",  httpMethod = "GET")
	public BocloudResult<List<HmcVirtualFibreChannelMapping>> listByVios(@PathVariable(value = Common.ID) Long viosId) {
		return hmcVirtualFibreChannelMappingService.listByVios(viosId);
	}

	// 2019-08-15 : 去掉自动获取槽号的相关功能，这个接口不需要了。暂时屏蔽。 详见PBSM-5039
	// @Log(module = BoCloudService.IMS, target = "HMC虚拟光纤适配器", operation =
	// "查询虚拟光纤通道列表")
	// @RequestMapping(value = "/vios/{viosId}/partitions/{id}/vfcs", method =
	// {RequestMethod.GET})
	// public BocloudResult listByViosAndPartition(@RequestParam(value =
	// Common.PARAMS, required = false) String params,
	// @PathVariable(value = "viosId", required = true) Long viosId,
	// @PathVariable(value = Common.ID, required = true) Long partitionsId,
	// @Value(Common.REQ_CONTEXT) RequestContext context) {
	// return hmcVirtualFibreChannelMappingService.listByViosAndPartition(viosId,
	// partitionsId,
	// JSON.parseObject(params).getJSONArray("slots").toJavaList(Integer.class));
	// }

}
