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.entity.resource.azure.account.StorageAccountFirewall;
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(tags = {"CMC", "CSC"}, value = "自定义域名storageAccount", 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(tags = {"CMC", "CSC"}, value = "TLS设置storageAccount", 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);
    }


    /**
     * 再生密钥
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "再生密钥storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "再生密钥storageAccount")
    @PostMapping(value = "/{id}/regenerate/keys")
    public BocloudResult regenerateKey(@PathVariable(value = Common.ID) Long id,
                                       @RequestBody StorageAccount modifyParams,
                                       @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.regenerateKey(modifyParams, context);
    }


    /**
     * 所选网络-》附加虚拟网络子网
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "附加虚拟网络子网storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "附加虚拟网络子网storageAccount")
    @PostMapping(value = "/{id}/with/access/subnet")
    public BocloudResult withAccessFromNetworkSubnet(@PathVariable(value = Common.ID) Long id,
                                                     @RequestBody StorageAccount modifyParams,
                                                     @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.withAccessFromNetworkSubnet(modifyParams, context);
    }

    /**
     * 所选网络-》删除虚拟网络子网
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除虚拟网络子网storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "删除虚拟网络子网storageAccount")
    @PostMapping(value = "/{id}/without/access/subnet")
    public BocloudResult withoutNetworkSubnetAccess(@PathVariable(value = Common.ID) Long id,
                                                    @RequestBody StorageAccount modifyParams,
                                                    @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.withoutNetworkSubnetAccess(modifyParams, context);
    }

    /**
     * 全部网络
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "设置全部网络storageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "全部网络storageAccount")
    @PostMapping(value = "/{id}/with/access/all/network")
    public BocloudResult withAccessFromAllNetworks(@PathVariable(value = Common.ID) Long id,
                                                   @RequestBody StorageAccount modifyParams,
                                                   @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.withAccessFromAllNetworks(modifyParams, context);
    }


    /**
     * 添加IP
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "添加IPstorageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "添加IPstorageAccount")
    @PostMapping(value = "/{id}/with/access/ip/address")
    public BocloudResult withAccessFromIpAddress(@PathVariable(value = Common.ID) Long id,
                                                 @RequestBody StorageAccountFirewall modifyParams,
                                                 @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.withAccessFromIpAddress(modifyParams, context);
    }

    /**
     * 删除IP
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除IPstorageAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "storageAccount", operation = "删除IPstorageAccount")
    @PostMapping(value = "/{id}/with/out/ip/address")
    public BocloudResult withoutIpAddressAccess(@PathVariable(value = Common.ID) Long id,
                                                @RequestBody StorageAccountFirewall modifyParams,
                                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.withoutIpAddressAccess(modifyParams, context);
    }

}