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

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.ResultTools;
import com.bocloud.ims.entity.resource.BackupVaults;
import com.bocloud.ims.interfaces.resource.BackupVaultsService;
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.*;

@RestController
@RequestMapping("/v1/backup/vaults")
@Api(value = "BackupVaults管理", tags = "BackupVaults管理")
public class BackupVaultsController {

    @Autowired
    private BackupVaultsService backupVaultsService;

    /**
     * 查询BackupVaults列表
     *
     * @param pager
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "BackupVaults列表查询",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "BackupVaults管理", operation = "查询BackupVaults列表")
    @GetMapping
    public BocloudResult<GridBean<BackupVaults>> list(Pager pager, @Value(Common.REQ_CONTEXT) RequestContext context) {
        return backupVaultsService.list(pager, context);
    }

    /**
     * 保存BackupVaults
     *
     * @param backupVaults
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "保存BackupVaults",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "BackupVaults管理", operation = "保存BackupVaults")
    @PostMapping
    public BocloudResult create(@RequestBody BackupVaults backupVaults,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return backupVaultsService.create(backupVaults, context);
    }

    /**
     * 存储库绑定资源
     *
     * @param backupVaultParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "存储库绑定资源",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "存储库绑定资源", operation = "存储库绑定资源")
    @PostMapping("/addResources")
    public BocloudResult<String> addResources(@RequestBody BackupVaults backupVaultParam,
                                              @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != backupVaultParam) {
            return backupVaultsService.addResources(backupVaultParam, context);
        } else {
            return ResultTools.formatErrResult();
        }
    }

    /**
     * 存储库绑定资源
     *
     * @param backupVaultParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "存储库扩容",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "存储库扩容", operation = "存储库扩容")
    @PostMapping("/extend")
    public BocloudResult<String> extend(@RequestBody BackupVaults backupVaultParam,
                                        @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != backupVaultParam) {
            return backupVaultsService.extend(backupVaultParam, context);
        } else {
            return ResultTools.formatErrResult();
        }
    }

    /**
     * 存储库绑定资源
     *
     * @param backupVaultParam
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "资源备份",  httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "存储库绑定资源", operation = "存储库绑定资源")
    @PostMapping("/backup")
    public BocloudResult<String> backup(@RequestBody BackupVaults backupVaultParam,
                                        @Value(Common.REQ_CONTEXT) RequestContext context) {
        if (null != backupVaultParam) {
            return backupVaultsService.backup(backupVaultParam, context);
        } else {
            return ResultTools.formatErrResult();
        }
    }

    /**
     * 删除BackupVaults
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "删除备份存储库",  httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "BackupVaults管理", operation = "删除BackupVaults")
    @DeleteMapping(value = "/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return backupVaultsService.remove(id, context);
    }

    /**
     * 更新BackupVaults
     *
     * @param id
     * @param backupVaults
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "更新备份存储库",  httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "BackupVaults管理", operation = "更新BackupVaults")
    @PutMapping(value = "/{id}")
    public BocloudResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody BackupVaults backupVaults,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        backupVaults.setId(id);
        return backupVaultsService.modify(backupVaults, context);
    }

    /**
     * 查询BackupVaults详情
     *
     * @param id
     * @return
     */
    @ApiOperation(tags = {"CMC",
            "CSC"}, value = "查询备份存储库详情",  httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "BackupVaults管理", operation = "查询BackupVaults详情")
    @GetMapping(value = "/{id}")
    public BocloudResult<BackupVaults> detail(@PathVariable(value = Common.ID) Long id) {
        return backupVaultsService.detail(id);
    }

}
