package com.njcn.product.event.transientes.controller;

import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.product.event.transientes.pojo.po.MsgEventConfig;
import com.njcn.product.event.transientes.service.MsgEventConfigService;
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.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: cdf
 * @CreateTime: 2025-06-27
 * @Description:
 */
@Api(tags = "暂降平台配置")
@RequestMapping("config")
@RestController
@RequiredArgsConstructor
@Slf4j
public class MsgEventConfigController extends BaseController {

    private final MsgEventConfigService msgEventConfigService;

    @OperateInfo(operateType = OperateType.ADD)
    @PostMapping("/eventConfig")
    @ApiOperation("暂降平台配置")
    @ApiImplicitParam(name = "msgEventConfig", value = "实体", required = true)
    @Transactional(rollbackFor = Exception.class)
    public HttpResult<Object> eventConfig(@RequestBody @Validated MsgEventConfig msgEventConfig) {
        String methodDescribe = getMethodDescribe("eventConfig");
        msgEventConfigService.eventConfig(msgEventConfig);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    @OperateInfo
    @GetMapping("/queryConfig")
    @ApiOperation("接收远程推送的暂态事件")
    public HttpResult<MsgEventConfig> queryConfig() {
        String methodDescribe = getMethodDescribe("queryConfig");
        MsgEventConfig msgEventConfig = msgEventConfigService.queryConfig();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, msgEventConfig, methodDescribe);
    }
}
