package cn.axzo.msg.center.message.controller;

import cn.axzo.msg.center.message.domain.param.BizEventMappingQueryParam;
import cn.axzo.msg.center.message.domain.param.BizEventSaveOrUpdateParam;
import cn.axzo.msg.center.message.service.BizEventMappingService;
import cn.axzo.msg.center.service.bizevent.client.BizEventMappingClient;
import cn.axzo.msg.center.service.bizevent.request.BizEventMappingCreateRequest;
import cn.axzo.msg.center.service.bizevent.request.BizEventMappingPageRequest;
import cn.axzo.msg.center.service.bizevent.request.BizEventMappingPageResponse;
import cn.axzo.msg.center.service.bizevent.request.BizEventMappingRemoveRequest;
import cn.axzo.msg.center.service.bizevent.request.BizEventMappingUpdateRequest;
import cn.azxo.framework.common.model.CommonResponse;
import cn.azxo.framework.common.model.Page;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息业务事件管理
 *
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class BizEventMappingController implements BizEventMappingClient {

    private final BizEventMappingService bizEventMappingService;

    @Override
    public CommonResponse<String> save(BizEventMappingCreateRequest param) {
        log.info("BizEventMappingCreate param= [{}]", JSONUtil.toJsonStr(param));
        return CommonResponse.success(bizEventMappingService.create(BeanUtil.copyProperties(param,
                BizEventSaveOrUpdateParam.class)));
    }

    @Override
    public CommonResponse<Void> update(BizEventMappingUpdateRequest param) {
        log.info("BizEventMappingUpdate param= [{}]", JSONUtil.toJsonStr(param));
        param.check();
        bizEventMappingService.update(BeanUtil.copyProperties(param,
                BizEventSaveOrUpdateParam.class));
        return CommonResponse.success();
    }

    @Override
    public CommonResponse<Page<BizEventMappingPageResponse>> page(
            BizEventMappingPageRequest param) {
        return CommonResponse.success(bizEventMappingService.page(BeanUtil.copyProperties(param,
                BizEventMappingQueryParam.class)));
    }

    @Override
    public CommonResponse<Void> remove(BizEventMappingRemoveRequest param) {
        log.info("BizEventMappingRemove param= [{}]", JSONUtil.toJsonStr(param));
        bizEventMappingService.remove(param);
        return CommonResponse.success();
    }
}
