package com.izouma.nineth.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.math.BigDecimal;


@Data
public class UserRankDTO implements  Comparable{
    /**
     * 排名
     */
    private int rank;
    /**
     * 用户id
     */
    @JsonIgnore
    private Long user_id;
    /**
     * 用户头像
     */
    private String avatar;
    /**
     * 昵称
     */
    private String nickname;
    /**
     * 数量
     */
    private BigDecimal amount = BigDecimal.ZERO;

    @Override
    public int compareTo(Object o) {
        if(o == null){
            return 1;
        }

        if(o instanceof UserRankDTO){
            UserRankDTO userRankDTO = (UserRankDTO)o;
            if(this.getAmount() == userRankDTO.getAmount()){
                return 0;
            }
            if(userRankDTO.getAmount() == null){
                return 1;
            }
            if(this.getAmount() == null){
                return -1;
            }
            return this.getAmount().compareTo(userRankDTO.getAmount());
        }

        return 1;
    }
}
