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

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.monitor.Alarm;
import com.bocloud.ims.interfaces.resource.azure.monitor.AlarmService;
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 java.util.List;

/**
 * @Company: 博云 www.bocloud.com
 * @ClassName: AlarmController
 * @Description:
 * @author: zhenpingLi/李振平
 * @date: 2021/1/20 13:58
 */
@Api(value = "alarm", tags = "alarm管理")
@RestController
@RequestMapping("/v1/azure/metric/alarms")
public class AlarmController {
    @Autowired
    private AlarmService service;

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

    /**
     * 删除
     *
     * @param id
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "删除alarm", httpMethod = "DELETE")
    @Log(module = BoCloudService.IMS, target = "alarm", operation = "删除alarm")
    @DeleteMapping("/{id}")
    public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
                                @Value(Common.REQ_CONTEXT) RequestContext context) {
        return service.remove(id, context);
    }


    /**
     * 批量确认状态
     *
     * @param
     * @param context
     * @return
     */
    @ApiOperation(tags = {"CMC", "CSC"}, value = "批量确认状态metricAlert", httpMethod = "PUT")
    @Log(module = BoCloudService.IMS, target = "metricAlert", operation = "批量确认状态metricAlert")
    @PutMapping("/batch")
    public BocloudResult assignBatch(
            @RequestParam(value = "ids", required = false) List<Long> ids,
            @RequestParam(value = "status", required = false) String status,
            @Value(Common.REQ_CONTEXT) RequestContext context) {
        for (Long id : ids) {
            Alarm entityParams = new Alarm();
            entityParams.setStatus(status);
            entityParams.setId(id);
            service.modify(entityParams, context);
        }
        return new BocloudResult(true, "操作成功");
    }
}