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

import com.bocloud.cmp.params.azure.StorageAccountCheckNameParams;
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.account.StorageAccount;
import com.bocloud.ims.interfaces.resource.azure.account.StorageAccountService;
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: StorageAccountController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2020/7/24 14:16
 */
@Api(value = "storageAccount", tags = "storageAccount管理")
@RestController
@RequestMapping("/v1/storage/accounts")
public class StorageAccountController {

    @Autowired
    private StorageAccountService service;

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


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


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

    /**
     * 校验名称
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "校验名称storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "校验名称storageAccount")
    @PostMapping("/check/names")
    public BocloudResult checkName(@RequestBody StorageAccountCheckNameParams params,
                                   @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.checkName(params, context);
    }


    /**
     * 用户分配
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "用户分配storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "用户分配storageAccount")
    @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 = "批量用户分配storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "批量用户分配storageAccount")
    @PostMapping("/users/batch")
    public BocloudResult assignBatch(
            @RequestBody UserAssignParams params,
            @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.assignBatch(params, context);
    }

    /**
     * 自定义域名
     *
     * @param modifyParams
     * @param context
     * @return
     */
    @ApiOperation(value = "自定义域名", response = BocloudResult.class, httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "自定义域名storageAccount")
    @PutMapping(value = "/{id}/custom/domain")
    public BocloudResult customDomain(@PathVariable(value = Common.ID) Long id,
                                      @RequestBody StorageAccount modifyParams,
                                      @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.customDomain(modifyParams, context);
    }

    /**
     * tls设置
     *
     * @param modifyParams
     * @param context
     * @return
     */
    @ApiOperation(value = "TLS设置", response = BocloudResult.class, httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "TLS设置storageAccount")
    @PutMapping(value = "/{id}/tls")
    public BocloudResult minimumTlsVersion(@PathVariable(value = Common.ID) Long id,
                                           @RequestBody StorageAccount modifyParams,
                                           @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.minimumTlsVersion(modifyParams, context);
    }


}