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.HmcVirtualSwitch;
import com.bocloud.ims.interfaces.resource.hmc.HmcVirtualSwitchService;
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/switchs")
@Api(value = "HMC虚拟交换机", tags = "HMC虚拟交换机")
public class HmcVirtualSwitchController {
	@Autowired
	private HmcVirtualSwitchService hmcVirtualSwitchService;

	/**
	 * 列表
	 *
	 * @param pager
	 *            分页参数
	 * @return 数据结果集
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "查询")
	@RequestMapping(method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "查询",  httpMethod = "GET")
	public BocloudResult<GridBean<HmcVirtualSwitch>> list(Pager pager) {
		return hmcVirtualSwitchService.list(pager);
	}

	/**
	 * 添加虚拟交换机
	 * 
	 * @param virtualSwitch
	 * @return 添加结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "创建")
	@RequestMapping(method = { RequestMethod.POST })
	@ApiOperation(tags={"CMC","CSC"},value = "创建",  httpMethod = "POST")
	public BocloudResult create(@RequestBody HmcVirtualSwitch virtualSwitch,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcVirtualSwitchService.create(virtualSwitch, context);
	}

	/**
	 * 修改虚拟交换机
	 *
	 * @param vswitch
	 *            逻辑分区属性信息的json字符串，在数据转换时会发生异常，对外抛出400异常【Bad Request】
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "修改")
	@RequestMapping(value = "/{id}", method = { RequestMethod.PUT })
	@ApiOperation(tags={"CMC","CSC"},value = "修改",  httpMethod = "PUT")
	public BocloudResult modify(@RequestBody HmcVirtualSwitch vswitch,
								@Value(Common.REQ_CONTEXT) RequestContext context) {
			return hmcVirtualSwitchService.modify(vswitch, context);
	}

	/**
	 * 删除虚拟交换机
	 * 
	 * @param id
	 *            虚拟交换机ID
	 * @return 操作结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "删除")
	@RequestMapping(value = "/{id}", method = { RequestMethod.DELETE })
	@ApiOperation(tags={"CMC","CSC"},value = "删除",  httpMethod = "DELETE")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return hmcVirtualSwitchService.remove(id, context);
	}

	/**
	 * 详细信息
	 * 
	 * @param id
	 * @return 操作结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "详情")
	@RequestMapping(value = "/{id}", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "详情",  httpMethod = "GET")
	public BocloudResult<HmcVirtualSwitch> detail(@RequestParam Long serverId,
			@PathVariable(value = Common.ID) Long id) {
		return hmcVirtualSwitchService.detail(id, serverId);
	}

	/**
	 * 查看虚拟交换机中可用的vlanId
	 *
	 * @param id
	 * @return 操作结果
	 */
	@Log(module = BoCloudService.IMS, target = "HMC虚拟交换机", operation = "按虚拟交换机查询可用的vlanId")
	@RequestMapping(value = "/{id}/vlanIds", method = { RequestMethod.GET })
	@ApiOperation(tags={"CMC","CSC"},value = "按虚拟交换机查询可用的vlanId",  httpMethod = "GET")
	public BocloudResult<List<Integer>> getVlanIds(@PathVariable(value = Common.ID) Long id) {
		return hmcVirtualSwitchService.getVlanIds(id);
	}
}
