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

import com.bocloud.cmp.params.azure.DbConfigurationParams;
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.db.DbConfiguration;
import com.bocloud.ims.interfaces.resource.azure.db.DbConfigurationService;
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.web.bind.annotation.*;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: DbConfigurationController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/2/4 18:14
 */
@Api(value = "DatabaseConfiguration", tags = "DatabaseConfiguration管理")
@RestController
@RequestMapping("/v1/cloud/database/server/configurations")
public class DbConfigurationController {

    @Autowired
    private DbConfigurationService service;

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


    /**
     * 创建
     *
     * @param params
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "创建DatabaseConfiguration", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "DatabaseConfiguration", operation = "创建DatabaseConfiguration")
    @PostMapping
    public BocloudResult create(@RequestBody DbConfiguration params,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(params, context);
    }

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


}