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

import com.bocloud.cmp.params.fusionsphere.HostOperationParams;
import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.entity.resource.Server;
import com.bocloud.ims.interfaces.resource.fusionsphere.FusionSphereHostService;
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.*;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: FusionSphereHostController
 * @Description:主机管理
 * @author: zhenpingLi/李振平
 * @date: 2021/10/20 10:20
 */
@Api(value = "FusionSphereHost", tags = "FusionSphereHost管理")
@RestController
@RequestMapping("/v1/fc/hosts")
public class FusionSphereHostController {

    @Autowired
    private FusionSphereHostService service;

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "列表FusionSphereHost", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "列表FusionSphereHost")
    @GetMapping
    public BocloudResult list(Pager pager,
                              @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.list(pager, context);
    }


    /**
     * 查询详情
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "详情FusionSphereHost", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "详情FusionSphereHost")
    @GetMapping("/{id}")
    public BocloudResult detail(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.detail(id, context);
    }

    /**
     * 创建
     *
     * @param entityParams
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建FusionSphereHost", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "创建FusionSphereHost")
    @PostMapping
    public BocloudResult create(@RequestBody Server entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(entityParams, context);
    }

    /**
     * 更新
     *
     * @param entityParams
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "更新FusionSphereHost", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "更新FusionSphereHost")
    @PutMapping(value = "/{id}")
    public BocloudResult modify(@PathVariable(value = Common.ID) Long id,
                                @RequestBody Server entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.modify(entityParams, context);
    }

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


    /**
     * 操作
     *
     * @param entityParams
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "操作FusionSphereHost", httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "操作FusionSphereHost")
    @PatchMapping(value = "/{id}")
    public BocloudResult operations(@PathVariable(value = Common.ID) Long id,
                                    @RequestBody HostOperationParams entityParams,
                                    @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.operations(entityParams, context);
    }

    /**
     * 根据存储设备查询主机
     *
     * @param id 存储设备id
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "根据存储设备查询主机", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "FusionSphereHost", operation = "根据存储设备查询主机")
    @GetMapping("/listByStdId")
    public BocloudResult listByStorageDeviceId(Long id,
                                               @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.listByStorageDeviceId(id, context);
    }
}