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

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.slb.BackEnd;
import com.bocloud.ims.interfaces.resource.azure.slb.BackEndService;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;

@Api(value = "后端池", tags = "后端池管理")
@RestController
@RequestMapping("/v1/backends")
public class BackEndController {

    @Autowired
    private BackEndService 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 params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建后端池", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "后端池", operation = "创建后端池")
    @PostMapping
    public BocloudResult create(@RequestBody BackEnd 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 entityParams
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "更新", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "后端池", operation = "创建后端池")
    @PutMapping(value = "/{id}")
    public BocloudResult modify(@PathVariable(value = Common.ID) Long id,
                                @RequestBody BackEnd entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.modify(entityParams, context);
    }


    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询修改后端池未绑定的云主机", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "后端池", operation = "查询修改后端池未绑定的云主机")
    @GetMapping("/{id}/vms")
    public BocloudResult getUnbindVm(@PathVariable(value = Common.ID) Long id, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.getModifyUnbindVm(id, context);
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询创建后端池未绑定的云主机", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "后端池", operation = "查询创建后端池未绑定的云主机")
    @GetMapping("/{id}/create/vms")
    public BocloudResult getCreateUnbindVm(@PathVariable(value = Common.ID) Long id,
                                           @RequestParam(value = "vpcId", required = false) Long vpcId,
                                           @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.getCreateUnbindVm(id,vpcId, context);
    }


}
