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.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.entity.resource.hmc.HmcHostEthernetAdapter;
import com.bocloud.ims.interfaces.resource.hmc.HmcHEAService;
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 HmcHEAController {
    @Autowired
    private HmcHEAService hmcHEAService;

    /**
     * 列表主机以太网逻辑端口
     * 
     * @return 列表结果
     */
    @Log(module = BoCloudService.IMS, target = "HMC主机以太网适配器", operation = "创建")
    @RequestMapping(value = "/servers/{id}/heas", method = { RequestMethod.GET })
    @ApiOperation(tags={"CMC","CSC"},value = "创建主机以太网适配器",  httpMethod = "GET")
    public BocloudResult<List<HmcHostEthernetAdapter>> list(
            @PathVariable(value = Common.ID) Long serverId) {
        return hmcHEAService.listPhysicalPorts(serverId);
    }

    /**
     * 修改物理主机以太网端口
     *
     * @param hmcHea
     *            逻辑分区属性信息的json字符串，在数据转换时会发生异常，对外抛出400异常【Bad Request】
     * @param id
     *            需要修改的逻辑分区ID
     */
    @Log(module = BoCloudService.IMS, target = "HMC主机以太网适配器", operation = "修改")
    @RequestMapping(value = "/heas/{id}", method = { RequestMethod.PUT })
    @ApiOperation(tags={"CMC","CSC"},value = "修改主机以太网适配器",  httpMethod = "PUT")
    public BocloudResult modify(@RequestBody HmcHostEthernetAdapter hmcHea,
                                @PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
            return hmcHEAService.modify(hmcHea, context);
    }
}
