package org.xyzh.common.dto.usercenter;

import org.xyzh.common.dto.BaseDTO;
import java.util.Date;

/**
 * @description 用户成就进度表 - 追踪用户朝向成就的进度
 * @filename TbUserAchievementProgress.java
 * @author yslg
 * @copyright xyzh
 * @since 2025-10-24
 */
public class TbUserAchievementProgress extends BaseDTO {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * @description 用户ID
     */
    private String userID;
    
    /**
     * @description 成就ID
     */
    private String achievementID;
    
    /**
     * @description 当前进度值
     */
    private Integer currentValue;
    
    /**
     * @description 目标进度值（冗余字段，方便查询）
     */
    private Integer targetValue;
    
    /**
     * @description 进度百分比 (0-100)
     */
    private Integer progressPercentage;
    
    /**
     * @description 是否已完成
     */
    private Boolean completed;
    
    /**
     * @description 最后更新时间
     */
    private Date lastUpdateTime;

    public String getUserID() {
        return userID;
    }

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

    public String getAchievementID() {
        return achievementID;
    }

    public void setAchievementID(String achievementID) {
        this.achievementID = achievementID;
    }

    public Integer getCurrentValue() {
        return currentValue;
    }

    public void setCurrentValue(Integer currentValue) {
        this.currentValue = currentValue;
        updateProgressPercentage();
    }

    public Integer getTargetValue() {
        return targetValue;
    }

    public void setTargetValue(Integer targetValue) {
        this.targetValue = targetValue;
        updateProgressPercentage();
    }

    public Integer getProgressPercentage() {
        return progressPercentage;
    }

    public void setProgressPercentage(Integer progressPercentage) {
        this.progressPercentage = progressPercentage;
    }

    public Boolean getCompleted() {
        return completed;
    }

    public void setCompleted(Boolean completed) {
        this.completed = completed;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    /**
     * 更新进度百分比
     */
    private void updateProgressPercentage() {
        if (currentValue != null && targetValue != null && targetValue > 0) {
            this.progressPercentage = Math.min(100, (int) ((currentValue * 100.0) / targetValue));
            this.completed = currentValue >= targetValue;
        }
    }

    @Override
    public String toString() {
        return "TbUserAchievementProgress{" +
                "id=" + getID() +
                ", userID='" + userID + '\'' +
                ", achievementID='" + achievementID + '\'' +
                ", currentValue=" + currentValue +
                ", targetValue=" + targetValue +
                ", progressPercentage=" + progressPercentage +
                ", completed=" + completed +
                ", lastUpdateTime=" + lastUpdateTime +
                '}';
    }
}

