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

import com.alibaba.fastjson.JSONObject;
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.common.utils.JSONTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.entity.resource.f5.BiPool;
import com.bocloud.ims.interfaces.resource.f5.F5BiPoolService;
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 = "F5BiPool", tags = "F5BiPool")
@RestController
@RequestMapping("/v1/f5/pools")
public class F5BiPoolController {
    @Autowired
    private F5BiPoolService f5BiPoolService;

    /**
     * 列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "分页查询F5BiPool", httpMethod = "GET")
    @GetMapping
    public BocloudResult<GridBean<BiPool>> list(Pager pager) {
        return f5BiPoolService.list(pager);
    }

    /**
     * 添加
     *
     * @param biPool
     * @param context
     * @return 添加结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "添加BiPool", httpMethod = "POST")
    @PostMapping
    public BocloudResult create(@RequestBody BiPool biPool,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != biPool) {
            return f5BiPoolService.create(biPool, context.getTarget());
        } else {
            return ResultTools.formatErrResult();
        }
    }

    /**
     * 修改
     *
     * @param biPool
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "修改BiPool", httpMethod = "PUT")
    @PutMapping(value = "/{id}")
    public BocloudResult modify(@RequestBody BiPool biPool,
                                @PathVariable(value = Common.ID) Long id, @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != biPool) {
            biPool.setId(id);
            return f5BiPoolService.modify(biPool, context.getTarget());
        } else {
            return ResultTools.formatErrResult();
        }
    }

    /**
     * 移除
     *
     * @param id
     * @param context
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "移除BiPool", httpMethod = "DELETE")
    @DeleteMapping(value = "/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return f5BiPoolService.remove(id, context.getTarget());
    }

    /**
     * 详细信息
     *
     * @param id
     * @return 操作结果
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看bipool详情", httpMethod = "GET")
    @GetMapping(value = "/{id}")
    public BocloudResult<BiPool> detail(@PathVariable(value = Common.ID) Long id) {
        return f5BiPoolService.detail(id);
    }
}
