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

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.ClusterNode;
import com.bocloud.ims.interfaces.resource.ClusterNodeService;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "集群节点", tags = "集群节点")
@RestController
@RequestMapping("/v1/clusters/nodes")
public class ClusterNodeController {

    @Autowired
    private ClusterNodeService clusterNodeService;

    /**
     * 查看集群列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看集群节点列表",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "集群节点", operation = "查看集群列表")
    @GetMapping
    public BocloudResult<GridBean<ClusterNode>> list(Pager pager) {
        return clusterNodeService.list(pager);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看集群节点列表",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "集群节点", operation = "查看集群列表")
    @GetMapping("/condition")
    public BocloudResult<List<ClusterNode>> condition(@RequestParam(value = Common.CONDITION, required = false) String condition) {
        return clusterNodeService.condition(condition);
    }

    /**
     * 删除计算主机
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除主机",  httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "主机", operation = "删除主机")
    @DeleteMapping(value = "/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return clusterNodeService.remove(id, context);
    }

    /**
     * 查看集群详情
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看集群节点详情",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "集群节点", operation = "查看集群详情")
    @GetMapping("/{id}")
    public BocloudResult<ClusterNode> detail(@PathVariable(value = Common.ID) Long id) {
        return clusterNodeService.detail(id);
    }

}
