package com.red.circle.other.domain.rocket;

import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 贡献者值对象
 *
 * @author system
 * @date 2025-01-15
 */
@Data
public class RocketContributor {

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户名称
     */
    private String userName;

    /**
     * 用户头像
     */
    private String userAvatar;

    /**
     * 贡献能量值
     */
    private Long energy;

    /**
     * 贡献率 (%)
     */
    private BigDecimal contributionRate;

    /**
     * 送礼次数
     */
    private Integer giftCount;

    /**
     * 首次贡献时间
     */
    private LocalDateTime firstContributeTime;

    /**
     * 最后贡献时间
     */
    private LocalDateTime lastContributeTime;

    /**
     * 增加能量
     */
    public void addEnergy(Long addEnergy) {
        if (this.energy == null) {
            this.energy = 0L;
        }
        this.energy += addEnergy;

        if (this.giftCount == null) {
            this.giftCount = 0;
        }
        this.giftCount++;

        this.lastContributeTime = LocalDateTime.now();
        if (this.firstContributeTime == null) {
            this.firstContributeTime = LocalDateTime.now();
        }
    }
}
