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.AutomationAccount;
import com.bocloud.ims.interfaces.resource.azure.automation.AutomationAccoutService;
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: AutomationAccoutController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2020/8/10 11:23
 */
@Api(value = "automationAccout", tags = "automationAccout管理")
@RestController
@RequestMapping("/v1/automation/accounts")
public class AutomationAccoutController {
    @Autowired
    private AutomationAccoutService service;

    /**
     * 查询列表
     *
     * @param pager
     * @return
     */

    @ApiOperation(tags = {"CMC", "CSC"}, value = "列表automationAccount", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "列表automationAccount")
    @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 = "详情automationAccount", httpMethod = "GET")
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "详情automationAccount")
    @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 = "创建automationAccount", httpMethod = "POST")
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "创建automationAccount")
    @PostMapping
    public BocloudResult create(@RequestBody AutomationAccount entityParams,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.create(entityParams, context);
    }

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

    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除automationAccount", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "删除automationAccount")
    @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 = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "automationAccount列表")
    @GetMapping("/list")
    public BocloudResult list(@RequestParam(value = Common.PARAMS) String params) {
        return service.list(params);
    }

    /**
     * 查询详情
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询详情", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "automationAccount详情")
    @PostMapping("/detail")
    public BocloudResult detail(@RequestParam(value = Common.PARAMS) String params) {
        return service.detail(params);
    }

    /**
     * 删除自动化账户
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "删除自动化账户", response = BocloudResult.class, httpMethod = "DELETE", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "删除自动化账户")
    @DeleteMapping("/remove")
    public BocloudResult remove(@RequestParam(value = Common.PARAMS) String params) {
        return service.remove(params);
    }

    /**
     * 查询部署计划历史记录详情里的计算机更新运行状态
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询部署计划历史记录详情里的计算机更新运行状态", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "查询部署计划历史记录详情里的计算机更新运行状态")
    @PostMapping("/status/counts")
    public BocloudResult getStatusCounts(@RequestParam(value = Common.PARAMS) String params) {
        return service.getStatusCounts(params);
    }

    /**
     * 查询部署计划历史记录详情里的计算机
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询部署计划历史记录详情里的计算机", response = BocloudResult.class, httpMethod = "GET", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "查询部署计划历史记录详情里的计算机")
    @PostMapping("/machine/runs")
    public BocloudResult softwareUpdateConfigurationMachineRuns(@RequestParam(value = Common.PARAMS) String params) {
        return service.softwareUpdateConfigurationMachineRuns(params);
    }

    /**
     * //查询虚拟机更新代理准备
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "//查询虚拟机更新代理准备", response = BocloudResult.class, httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @Log(module = BoCloudService.IMS, target = "automationAccount", operation = "//查询虚拟机更新代理准备")
    @PostMapping("/machine/runbook")
    public BocloudResult hybridRunbookWorkerGroups(@RequestParam(value = Common.PARAMS) String params) {
        return service.hybridRunbookWorkerGroups(params);
    }


}