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.BiTunnel;
import com.bocloud.ims.interfaces.resource.f5.F5BiTunnelService;
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 = "BiTunnel", tags = "BiTunnel")
@RestController
@RequestMapping("/v1/f5/tunnels")
public class F5BiTunnelController {
    @Autowired
    private F5BiTunnelService f5BiTunnelService;

    /**
     * 列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查看Bitunnes列表", httpMethod = "GET")
    @GetMapping
    public BocloudResult<GridBean<BiTunnel>> list(Pager pager) {
        return f5BiTunnelService.list(pager);
    }

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

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

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

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

}
