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

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bocloud.cmp.params.azure.AzureRouterTableOperationParams;
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.network.RouterTable;
import com.bocloud.ims.interfaces.resource.azure.network.RouterTableService;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: RouterTableController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/1/5 10:11
 */
@Api(value = "routerTable", tags = "routerTable管理")
@RestController
@RequestMapping("/v1/router/tables")
public class RouterTableController {

    @Autowired
    private RouterTableService service;

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询列表",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "routerTable", operation = "routerTable列表")
    @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 = "routerTable", operation = "查询routerTable详情")
    @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 = "routerTable", operation = "创建routerTable")
    @PostMapping
    public BocloudResult create(@RequestBody RouterTable params, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(params, context);
    }

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

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


    /**
     * 操作
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "操作",  httpMethod = "PATCH")
    @Log(module = BoCloudService.IMS, target = "routerTable", operation = "操作routerTable")
    @PatchMapping(value = "/{id}")
    public BocloudResult operation(@PathVariable(value = Common.ID) Long id,
                                   @RequestBody AzureRouterTableOperationParams params,
                                   @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.operation(params, context);
    }

    /**
     * 用户分配
     *
     * @param id
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "routerTable用户分配",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "routerTable", operation = "routerTable用户分配")
    @PostMapping("/{id}/users")
    public BocloudResult assign(@PathVariable(value = Common.ID) Long id,
                                @RequestBody AzureRouterTableOperationParams params,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.assign(params, context);
    }

    /**
     * 用户分配
     *
     * @param
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "routerTable用户分配",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "routerTable", operation = "routerTable用户分配")
    @PostMapping("/users/batch")
    public BocloudResult assignBatch(@RequestBody AzureRouterTableOperationParams params,
            @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.batchAssign(params, context);
    }


}