package cn.axzo.msg.center.message.domain.param;

import cn.axzo.msg.center.domain.entity.BizEventMapping;
import cn.axzo.msg.center.service.bizevent.request.ReachDto;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;

/**
 * @author syl
 * @date 2023/12/14
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class BizEventSaveOrUpdateParam {

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 操作者的自然人id
     */
    private Long operatorId;

    /**
     * 业务事件code
     * 尽量保证唯一
     */
    private String bizCode;

    /**
     * 业务事件名称
     */
    private String bizName;

    /**
     * 业务动作配置
     */
    private List<ReachDto> reachConfig;

    /**
     * 是否删除
     */
    private Boolean isDelete;

    public BizEventMapping convertUpdateEntity(BizEventMapping exist){
        BizEventMapping entity = BeanUtil.copyProperties(this, BizEventMapping.class);
        entity.setUpdaterId(operatorId);
        if (BooleanUtils.isTrue(isDelete)) {
            entity.setIsDelete(exist.getId());
        }
        entity.setId(exist.getId());
        return entity;
    }
}
