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

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.automation.DeploymentPlan;
import com.bocloud.ims.interfaces.resource.azure.automation.DeploymentService;
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.*;


/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: DeploymentController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2020/8/11 18:16
 */
@Api(value = "deployment", tags = "deployment管理")
@RestController
@RequestMapping("/v1/azure/deployments")
public class DeploymentController {

    @Autowired
    private DeploymentService service;

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "列表deployment", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "列表deployment")
    @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 = "详情deployment", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "详情deployment")
    @GetMapping("/{id}")
    public BocloudResult detail(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.detail(id, context);
    }

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

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

    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除deployment", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "删除deployment")
    @DeleteMapping("/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.remove(id, context);
    }
    //----------------星巴克poc专用 ，数据不入库-------------------------------------------------------------

    /**
     * 查询列表
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询列表", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "deployment列表")
    @PostMapping("/list/plans")
    public BocloudResult listDeploymentPlan(@RequestParam(value = Common.PARAMS) String params) {
        return service.listDeploymentPlan(params);
    }

    /**
     * 查询共享密钥
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询共享密钥", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "deployment共享密钥")
    @PostMapping("/plans")
    public BocloudResult createDeploymentPlan(@RequestParam(value = Common.PARAMS) String params) {
        return service.createDeploymentPlan(params);
    }


    /**
     * 删除部署计划
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "删除部署计划", response = BocloudResult.class, httpMethod = "DELETE", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "deploymentPlan", operation = "删除部署计划")
    @DeleteMapping("/plans")
    public BocloudResult removeDeploymentPlan(@RequestParam(value = Common.PARAMS) String params) {
        return service.removeDeploymentPlan(params);
    }

    /**
     * 关联自动化账户
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "关联自动化账户", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "关联自动化账户")
    @PostMapping("/accounts")
    public BocloudResult deploymentAutomationAccount(@RequestParam(value = Common.PARAMS) String params) {
        return service.deploymentAutomationAccount(params);
    }


    /**
     * 查询部署计划执行记录
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询部署计划执行记录", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "deployment", operation = "查询部署计划执行记录")
    @PostMapping("/plan/record")
    public BocloudResult softwareUpdateConfigurationRuns(@RequestParam(value = Common.PARAMS) String params) {
        return service.softwareUpdateConfigurationRuns(params);
    }
}