package com.njcn.gather.system.cfg.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.LogUtil;
import com.njcn.gather.system.cfg.pojo.param.SysTestConfigParam;
import com.njcn.gather.system.cfg.pojo.po.SysTestConfig;
import com.njcn.gather.system.cfg.service.ISysTestConfigService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.HttpResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * @author caozehui
 * @date 2024-11-16
 */
@Slf4j
@Api(tags = "检测相关配置")
@RestController
@RequestMapping("/sysTestConfig")
@RequiredArgsConstructor
public class SysTestConfigController extends BaseController {
    private final ISysTestConfigService sysTestConfigService;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getConfig")
    @ApiOperation("获取检测相关配置信息")
    public HttpResult<SysTestConfig> getConfig() {
        String methodDescribe = getMethodDescribe("getConfig");
        LogUtil.njcnDebug(log, "{}", methodDescribe);
        SysTestConfig sysTestConfig = sysTestConfigService.getOneConfig();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sysTestConfig, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改检测相关配置信息")
    @ApiImplicitParam(name = "sysTestConfig", value = "检测相关配置信息", required = true)
    public HttpResult<Boolean> update(@RequestBody @Validated SysTestConfigParam.UpdateParam sysTestConfig) {
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}", methodDescribe);
        boolean result = sysTestConfigService.updateTestConfig(sysTestConfig);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取当前场景")
    @GetMapping("/getCurrentScene")
    public HttpResult<String> getCurrentScene() {
        String methodDescribe = getMethodDescribe("getCurrentScene");
        LogUtil.njcnDebug(log, "{}", methodDescribe);
        String currrentScene = sysTestConfigService.getCurrrentScene();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, currrentScene, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("获取是否在检测时同时生成报告")
    @GetMapping("/getAutoGenerate")
    public HttpResult<Integer> getAutoGenerate() {
        String methodDescribe = getMethodDescribe("getAutoGenerate");
        LogUtil.njcnDebug(log, "{}", methodDescribe);
        Integer autoGenerate = sysTestConfigService.getAutoGenerate();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, autoGenerate, methodDescribe);
    }
}

