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

import com.bocloud.cmp.params.azure.AzureListPriceParams;
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.price.AzureResourcePrice;
import com.bocloud.ims.interfaces.resource.azure.prices.AzurePriceService;
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.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: AzurePriceController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/1/6 16:41
 */
@Api(value = "azurePrices", tags = "azurePrices管理")
@RestController
@RequestMapping("/v1/azure/prices")
public class AzurePriceController {

    @Autowired
    private AzurePriceService service;

    /**
     * 查询规格定价
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询规格定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询规格定价")
    @PostMapping("/flavors")
    public BocloudResult flavor(@RequestBody AzureListPriceParams params) {
        return service.flavors(params);
    }

    /**
     * 查询磁盘定价
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询磁盘定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询磁盘定价")
    @PostMapping("/volumes")
    public BocloudResult volumes(@RequestBody AzureListPriceParams params) {
        return service.volumes(params);
    }

    /**
     * 查询eip定价
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询规格定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询eip定价")
    @PostMapping("/eips")
    public BocloudResult eips(@RequestBody AzureListPriceParams params) {
        return service.eips(params);
    }


    /**
     * 查询redis定价
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询redis定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询redis定价")
    @PostMapping("/redis")
    public BocloudResult redis(@RequestBody AzureListPriceParams params) {
        return service.redis(params);
    }

    /**
     * 查询mysql存储定价
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询mysql存储定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询mysql存储定价")
    @PostMapping("/mysql/storages")
    public BocloudResult mysqlStorage(@RequestBody AzureListPriceParams params) {
        return service.mysqlStorage(params);
    }

    /**
     * 查询mysql-vcore
     *
     * @param params
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "查询mysql-vcore定价", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrice", operation = "查询mysql-vcore定价")
    @PostMapping("/mysql/vcores")
    public BocloudResult mysqlVcore(@RequestBody AzureListPriceParams params) {
        return service.mysqlVcore(params);
    }

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

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

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

    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除azurePrices", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "azurePrices", operation = "删除azurePrices")
    @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 = "批量删除azurePrices", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "azurePrices", operation = "批量删除azurePrices")
    @PostMapping("/batch/remove")
    public BocloudResult batchRemove(@RequestParam(value = Common.PARAMS) String params,
                                     @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.batchRemove(params, context);
    }


    /**
     * @param response
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "下载导入模板azurePrices", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "azurePrices", operation = "下载导入模板")
    @GetMapping("/download")
    public void downloadTemplate(HttpServletResponse response) {
        service.downloadTemplate(response);
    }

}