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

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.utils.Common;
import com.bocloud.ims.entity.resource.powervc.HostSeaAdapter;
import com.bocloud.ims.interfaces.resource.powervc.HostSeaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author luyanchao
 * @since 2019/3/4 11:23
 */
@RestController
@RequestMapping("/v1")
@Api(value = "Powervc主机以太网适配器", tags = "Powervc主机以太网适配器")
public class HostSeaController {

    private final HostSeaService hostSeaService;

    @Autowired
    public HostSeaController(HostSeaService hostSeaService) {
        this.hostSeaService = hostSeaService;
    }

    @Log(module = BoCloudService.IMS, target = "Powervc主机以太网适配器", operation = "按主机查询可用的主机以太网适配器")
    @RequestMapping(value = "/hosts/{id}/seas", method = {RequestMethod.GET})
    @ApiOperation(tags={"CMC","CSC"},value = "按主机查询可用的主机以太网适配器",  httpMethod = "GET")
    public BocloudResult<List<HostSeaAdapter>> listByServer(@PathVariable(value = Common.ID) long serverId, @RequestParam(value = Common.PARAMS) String params) {
        return hostSeaService.listByServerIdAndVlanId(serverId, JSON.parseObject(params).getIntValue("vlanId"));
    }

    @Log(module = BoCloudService.IMS, target = "Powervc主机以太网适配器", operation = "按网络查询设定的主机以太网适配器")
    @RequestMapping(value = "/networks/{id}/seas", method = {RequestMethod.GET})
    @ApiOperation(tags={"CMC","CSC"},value = "按网络查询设定的主机以太网适配器",  httpMethod = "GET")
    public BocloudResult<List<HostSeaAdapter>> listByNetwork(@PathVariable(value = Common.ID) long networkId) {
        return hostSeaService.listByNetworkId(networkId);
    }
}
