package org.xyzh.common.core.event;

import org.xyzh.common.core.enums.AchievementEventType;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @description 成就事件数据类
 * @filename AchievementEvent.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-24
 */
public class AchievementEvent {
    
    /**
     * 用户ID
     */
    private String userID;
    
    /**
     * 事件类型
     */
    private AchievementEventType eventType;
    
    /**
     * 事件值（如学习时长、资源数量等）
     */
    private Integer eventValue;
    
    /**
     * 事件时间
     */
    private Date eventTime;
    
    /**
     * 额外数据
     */
    private Map<String, Object> extraData;
    
    public AchievementEvent() {
        this.eventTime = new Date();
        this.extraData = new HashMap<>();
    }
    
    public AchievementEvent(String userID, AchievementEventType eventType, Integer eventValue) {
        this.userID = userID;
        this.eventType = eventType;
        this.eventValue = eventValue;
        this.eventTime = new Date();
        this.extraData = new HashMap<>();
    }
    
    /**
     * 构建器模式
     */
    public static class Builder {
        private final AchievementEvent event;
        
        public Builder(String userID, AchievementEventType eventType) {
            event = new AchievementEvent();
            event.userID = userID;
            event.eventType = eventType;
        }
        
        public Builder value(Integer value) {
            event.eventValue = value;
            return this;
        }
        
        public Builder extra(String key, Object value) {
            event.extraData.put(key, value);
            return this;
        }
        
        public Builder time(Date time) {
            event.eventTime = time;
            return this;
        }
        
        public AchievementEvent build() {
            return event;
        }
    }
    
    public static Builder builder(String userID, AchievementEventType eventType) {
        return new Builder(userID, eventType);
    }

    public String getUserID() {
        return userID;
    }

    public void setUserID(String userID) {
        this.userID = userID;
    }

    public AchievementEventType getEventType() {
        return eventType;
    }

    public void setEventType(AchievementEventType eventType) {
        this.eventType = eventType;
    }

    public Integer getEventValue() {
        return eventValue;
    }

    public void setEventValue(Integer eventValue) {
        this.eventValue = eventValue;
    }

    public Date getEventTime() {
        return eventTime;
    }

    public void setEventTime(Date eventTime) {
        this.eventTime = eventTime;
    }

    public Map<String, Object> getExtraData() {
        return extraData;
    }

    public void setExtraData(Map<String, Object> extraData) {
        this.extraData = extraData;
    }
    
    public Object getExtraData(String key) {
        return extraData.get(key);
    }
    
    public void putExtraData(String key, Object value) {
        this.extraData.put(key, value);
    }

    @Override
    public String toString() {
        return "AchievementEvent{" +
                "userID='" + userID + '\'' +
                ", eventType=" + eventType +
                ", eventValue=" + eventValue +
                ", eventTime=" + eventTime +
                ", extraData=" + extraData +
                '}';
    }
}

