package com.zhongshu.card.server.core.event;

import com.zhongshu.card.server.core.util.CommonUtil;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationEvent;

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

/**
 * 用户信息发送变化（如：姓名、人脸信息、绑定的卡片等）
 *
 * @author TRX
 * @date 2024/6/26
 */
public class UserInfoChangeSyncEvent extends ApplicationEvent {

    @Getter
    private List<String> userIds;

    @Getter
    private String projectOid;

    @Getter
    private String from;

    @Getter
    private Map<String, Object> map = new HashMap<String, Object>();

    public UserInfoChangeSyncEvent(Object source, List<String> userIds, String projectOid, String from) {
        super(source);
        this.userIds = userIds;
        this.projectOid = projectOid;
        this.from = from;
    }

    public UserInfoChangeSyncEvent(Object source, List<String> userIds, String projectOid, Map<String, Object> map) {
        super(source);
        this.userIds = userIds;
        this.projectOid = projectOid;
        this.map = map;
    }

    public String getGroupId() {
        String groupId = "";
        if (map != null && map.containsKey("groupId")) {
            groupId = (String) map.get("groupId");
        }
        if (StringUtils.isEmpty(groupId)) {
            groupId = CommonUtil.UUID();
        }
        return groupId;
    }
}
