package com.njcn.gather.system.reg.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.reg.pojo.param.SysRegResParam;
import com.njcn.gather.system.reg.pojo.po.SysRegRes;
import com.njcn.gather.system.reg.pojo.vo.SysRegResVO;
import com.njcn.gather.system.reg.service.ISysRegResService;
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.*;

import java.util.List;
import java.util.Map;


/**
 * @author caozehui
 * @date 2024-11-21
 */
@Slf4j
@Api(tags = "注册版本管理")
@RestController
@RequestMapping("/sysRegRes")
@RequiredArgsConstructor
public class SysRegResController extends BaseController {
    private final ISysRegResService sysRegResService;

//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @GetMapping("/list")
//    @ApiOperation("查询注册版本列表")
//    public HttpResult<SysRegResVO> listRegRes() {
//        String methodDescribe = getMethodDescribe("listRegRes");
//        LogUtil.njcnDebug(log, "{}，查询参数为空", methodDescribe);
//        SysRegResVO result = sysRegResService.listRegRes();
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
//    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getRegResByType")
    @ApiOperation("根据类型id查询配置")
    @ApiImplicitParam(name = "typeId", value = "类型id，字典值", required = true)
    public HttpResult<SysRegRes> getRegResByType(@RequestParam("typeId") String typeId) {
        String methodDescribe = getMethodDescribe("listByTypeId");
        LogUtil.njcnDebug(log, "{}，查询参数为：{}", methodDescribe, typeId);
        SysRegRes result = sysRegResService.getRegResByType(typeId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

//    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
//    @PostMapping("/add")
//    @ApiOperation("新增注册版本")
//    @ApiImplicitParam(name = "sysRegRes", value = "注册版本对象", required = true)
//    public HttpResult<Boolean> addRegRes(@RequestBody @Validated SysRegResParam param) {
//        String methodDescribe = getMethodDescribe("addRegRes");
//        LogUtil.njcnDebug(log, "{}，新增参数为：{}", methodDescribe, param);
//        boolean result = sysRegResService.addRegRes(param);
//        if (result) {
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
//        } else {
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
//        }
//    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("修改配置")
    @ApiImplicitParam(name = "param", value = "注册版本更新对象", required = true)
    public HttpResult<Boolean> updateRegRes(@RequestBody @Validated SysRegResParam.UpdateParam param) {
        String methodDescribe = getMethodDescribe("updateRegRes");
        LogUtil.njcnDebug(log, "{}，更新参数为：{}", methodDescribe, param);
        boolean result = sysRegResService.updateRegRes(param);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }
}

