package com.reyun.saas.web.controller.user;

import com.reyun.saas.common.framework.ApiRestController;
import com.reyun.saas.common.restResult.PageParam;
import com.reyun.saas.common.restResult.RestResult;
import com.reyun.saas.mob.user.service.WarningConfigService;
import com.reyun.saas.mob.user.vo.WarningConfigParam;
import com.reyun.saas.mob.user.vo.WarningConfigVO;
import com.reyun.saas.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(value = "/warningConfig", tags = "预警配置")
@ApiRestController("warningConfig")
public class WarningConfigController {

    @Autowired
    private WarningConfigService warningConfigServiceImpl;

    @ApiOperation(value = "指标对码表", produces = "application/json",notes = "")
    @GetMapping("/findColumnCode/{os}")
    public RestResult find( @PathVariable String os){
        return warningConfigServiceImpl.findColumnCode(os);
    }

    @ApiOperation(value = "新增预警or模板", produces = "application/json",notes = "")
    @PostMapping("/create/{type}")
    public RestResult create( @RequestBody WarningConfigVO warningConfigVO,@ApiParam(value = "cfg:配置/tmp:模板/all:新建配置并保存模板") @PathVariable String type){
        return warningConfigServiceImpl.create(warningConfigVO,type,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "预警模板列表", produces = "application/json",notes = "")
    @GetMapping("/list/template")
    public RestResult listTemplate(PageParam pageParam, WarningConfigParam warningConfigParam){
        //筛选条件是否是多条件，还有搜索
        return warningConfigServiceImpl.listTemplate(pageParam,warningConfigParam,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "预警配置列表", produces = "application/json",notes = "")
    @GetMapping("/list/config")
    public RestResult listConfig(PageParam pageParam, WarningConfigParam warningConfigParam){
        //筛选条件是否是多条件，还有搜索
        return warningConfigServiceImpl.listConfig(pageParam,warningConfigParam,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "预警配置/模板 回显", produces = "application/json",notes = "")
    @GetMapping("/echo/{id}")
    public RestResult echo(@ApiParam(value = "配置/模板：取id属性")@PathVariable Long id){
        return warningConfigServiceImpl.echo(id,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "修改预警or模板", produces = "application/json",notes = "")
    @PostMapping("/update/{type}")
    public RestResult update( @RequestBody WarningConfigVO warningConfigVO,@ApiParam(value = "cfg:配置/tmp:模板/all:新建配置并保存模板") @PathVariable String type){
        return warningConfigServiceImpl.update(warningConfigVO,type,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "删除预警配置/模板", produces = "application/json",notes = "")
    @DeleteMapping("/delete")
    public RestResult delete(@ApiParam(value = "配置/模板：取id属性,逗号拼接")@RequestParam String ids){
        return warningConfigServiceImpl.delete(ids,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "开启/关闭 预警配置", produces = "application/json",notes = "")
    @PutMapping("/enable/{isusing}")
    public RestResult enable(@ApiParam(value = "配置/模板：取id属性,逗号拼接")@RequestParam String ids,@ApiParam(value = "开启true/关闭false")@PathVariable Boolean isusing){
        return warningConfigServiceImpl.enable(ids,isusing,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "模板下拉框", produces = "application/json",notes = "")
    @GetMapping("/select/template")
    public RestResult selectTemplate(@RequestParam String appkey,@RequestParam String cid,@RequestParam String os){
        return warningConfigServiceImpl.selectTemplate(SecurityUtils.getLoginUserId(),appkey,cid,os);
    }

    @ApiOperation(value = "预警分析列表", produces = "application/json",notes = "")
    @GetMapping("/list/analysis")
    public RestResult listAnalysis(PageParam pageParam, WarningConfigParam warningConfigParam){
        //筛选条件是否是多条件，还有搜索
        return warningConfigServiceImpl.listAnalysis(pageParam,warningConfigParam,SecurityUtils.getLoginUserId());
    }

    @ApiOperation(value = "预警分析列表-下钻", produces = "application/json",notes = "")
    @GetMapping("/list/analysis/nextLayer")
    public RestResult listAnalysisNextLayer(PageParam pageParam, WarningConfigParam warningConfigParam){

        return warningConfigServiceImpl.listAnalysisNextLayer(pageParam,warningConfigParam,SecurityUtils.getLoginUserId());
    }
}
