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

import com.bocloud.common.annotations.Log;
import com.bocloud.common.enums.BoCloudService;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.GridBean;
import com.bocloud.common.model.Pager;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.entity.resource.LbListenerPolicy;
import com.bocloud.ims.interfaces.resource.LbListenerPolicyService;
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.*;

@RestController
@RequestMapping("/v1/lb/listener/policy")
@Api(value = "负载均衡监听器策略", tags = "负载均衡监听器策略")
public class LbListenerPolicyController {


    @Autowired
    LbListenerPolicyService lbListenerPolicyService;
    
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "查询监听器策略列表", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "监听器策略", operation = "查看负载均衡监听器列表")
    @GetMapping
    public BocloudResult<GridBean<LbListenerPolicy>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) throws Exception {
        return lbListenerPolicyService.list(pager, context);
    }

    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "创建监听器策略", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "监听器策略", operation = "创建负载均衡监听器策略")
    @PostMapping
    public BocloudResult create(@RequestBody LbListenerPolicy policy,@Value(Common.REQ_CONTEXT) RequestContext context) throws Exception {
        return lbListenerPolicyService.create(policy, context);
    }

    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "更新监听器策略", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "监听器策略", operation = "更新负载均衡监听器策略")
    @PutMapping
    public BocloudResult modify(@RequestBody LbListenerPolicy policy,@Value(Common.REQ_CONTEXT) RequestContext context) throws Exception {
        return lbListenerPolicyService.modify(policy, context);
    }


    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "删除监听器策略", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "监听器策略", operation = "删除负载均衡监听器策略")
    @DeleteMapping("/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id, @Value(Common.REQ_CONTEXT) RequestContext context) throws Exception {
        return lbListenerPolicyService.remove(id, context);
    }
}
