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

import com.bocloud.cmp.params.azure.AzureDdosCustomPolicieOperationParams;
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.common.utils.ResultTools;
import com.bocloud.ims.entity.resource.azure.ddos.DdosCustomPolicie;
import com.bocloud.ims.interfaces.resource.azure.ddos.AzureDdosCustomPolicieService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * azureDDOS策略访问
 *
 * @author wangyu
 * @version 5.0.0-SNAPSHOT
 * @since 2021/2/2
 */
@RestController
@RequestMapping("/v1/azure/ddos-policies")
@Api(value = "DDOS策略管理管理", tags = "DDOS策略管理管理")
public class DdosCustomPolicieController {

    @Autowired
    private AzureDdosCustomPolicieService service;

    @ApiOperation(tags = {"CMC", "CSC"},value = "获取DDOS策略列表",httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "获取DDOS策略列表")
    @GetMapping
    public BocloudResult list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.list(pager, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"},value = "添加DDOS策略",httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "添加DDOS策略")
    @PostMapping
    public BocloudResult create(@RequestBody DdosCustomPolicie params, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(params, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"},value = "修改DDOS策略",httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "修改DDOS策略")
    @PutMapping("/{id}")
    public BocloudResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody DdosCustomPolicie params,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.modify(params, context);
    }

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

    @ApiOperation(tags = {"CMC", "CSC"},value = "查看DDOS策略详情",httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "查看DDOS策略详情")
    @GetMapping("/{id}")
    public BocloudResult detail(@PathVariable(value = Common.ID) Long id) {
        return service.detail(id);
    }

    @ApiOperation(tags = {"CMC", "CSC"},value = "批量删除DDOS策略",httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "批量删除DDOS策略")
    @DeleteMapping
    public BocloudResult batchRemove(@RequestBody AzureDdosCustomPolicieOperationParams params,
                                     @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.batchRemove(params, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"},value = "分配DDOS策略",httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "分配DDOS策略")
    @PostMapping("/{id}/users")
    public BocloudResult assign(@PathVariable(value = Common.ID) Long id, @RequestBody AzureDdosCustomPolicieOperationParams params, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != params) {
            return service.assign(params, context);
        } else {
            return ResultTools.formatErrResult();
        }
    }


    @ApiOperation(tags = {"CMC", "CSC"},value = "批量分配DDOS策略",httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "DDOS策略", operation = "批量分配DDOS策略")
    @PostMapping("/users/batch")
    public BocloudResult assignBatch(@RequestBody AzureDdosCustomPolicieOperationParams params, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != params) {
            return service.batchAssign(params, context);
        } else {
            return ResultTools.formatErrResult();
        }
    }

}
