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

import com.bocloud.cmp.params.azure.UserAssignParams;
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.azure.AvailabilitySet;
import com.bocloud.ims.interfaces.resource.azure.AvailabilitySetService;
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.*;

@Api(value = "可用性集", tags = "可用性集管理")
@RestController
@RequestMapping("/v1/availabilities/sets")
public class AvailabilitySetController {

    @Autowired
    private AvailabilitySetService service;

    /**
     * 列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "列表可用性集", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "可用性集", operation = "列表可用性集")
    @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 = "详情可用性集", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "可用性集", operation = "详情可用性集")
    @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 = "创建可用性集", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "可用性集", operation = "创建可用性集")
    @PostMapping
    public BocloudResult create(@RequestBody AvailabilitySet entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(entityParams, context);
    }

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


    /**
     * 用户分配
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "用户分配可用性集", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "可用性集", operation = "用户分配可用性集")
    @PostMapping("/{id}/users")
    public BocloudResult assign(@PathVariable(value = Common.ID) Long id,
                                @RequestBody UserAssignParams params,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.assign(params, context);
    }

    /**
     * 批量用户分配
     *
     * @param
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量用户分配可用性集", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "可用性集", operation = "批量用户分配可用性集")
    @PostMapping("/users/batch")
    public BocloudResult assignBatch(
            @RequestBody UserAssignParams params,
            @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.assignBatch(params, context);
    }

}
