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.utils.Common;
import com.bocloud.common.utils.JSONTools;
import com.bocloud.common.utils.ResultTools;
import com.bocloud.ims.interfaces.resource.f5.F5DeviceOverviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by liuyuanyuan on 2019/5/6 15:27
 */
@Api(value = "DeviceOverview", tags = "DeviceOverview")
@RestController
@RequestMapping("/v1/f5/devices/sync")
public class F5DeviceOverviewController {

    @Autowired
    private F5DeviceOverviewService f5DeviceOverviewService;

    @ApiOperation(tags = {"CMC", "CSC"}, value = "DeviceOverview", httpMethod = "GET")
    @GetMapping
    public BocloudResult<List<Object>> list(@RequestParam(value = "vendorId") Long vendorId) {
        if (null != vendorId) {
            return f5DeviceOverviewService.list(vendorId);
        } else {
            return ResultTools.formatErrResult();
        }
    }

    @ApiOperation(tags = {"CMC", "CSC"}, value = "主备同步", httpMethod = "PATCH")
    @PatchMapping
    public BocloudResult sync(@RequestParam(value = "deviceGroupName", required = false) String deviceGroupName,
                              @RequestParam(value = "vendorId", required = false) Long vendorId) {
        if (null != vendorId) {
            return f5DeviceOverviewService.sync(vendorId, deviceGroupName);
        } else {
            return ResultTools.formatErrResult();
        }
    }
}
