package cn.edu.hust.session;

import scala.math.Ordered;

public class CategorySortKey implements Ordered<CategorySortKey>, java.io.Serializable {
    // 定义三个 Long 类型的字段，表示点击数、订单数和支付数
    private Long clickCount;
    private Long orderCount;
    private Long payCount;
    // 实现 Ordered 接口中的 compare 方法，进行排序比较
    @Override
    public int compare(CategorySortKey categorySortKey) {
        // 先比较点击数，如果当前对象的点击数与传入对象的点击数不相等，则按点击数排序
        if(clickCount-categorySortKey.getClickCount()!=0)
        {
            return (int) (clickCount-categorySortKey.getClickCount());
        }
        // 如果点击数相等，再比较订单数1111
        else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()!=0)
        {
            return (int) (orderCount-categorySortKey.getOrderCount());
        }
        // 如果点击数和订单数都相等，再比较支付数
        else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()==0&&payCount-categorySortKey.getPayCount()!=0)
            return (int) (payCount-categorySortKey.getPayCount());
        return 0;// 如果点击数、订单数和支付数都相等，则返回 0，表示相等
    }
    @Override
    public boolean $less(CategorySortKey categorySortKey) {
        // 首先，比较点击数。如果当前对象的点击数小于传入对象的点击数，则当前对象"小于"传入对象
        if (clickCount < categorySortKey.getClickCount()) {
            return true;  // 返回true，表示当前对象小于传入对象
        }
        // 如果点击数相等，则比较订单数。如果当前对象的订单数小于传入对象的订单数，则当前对象"小于"传入对象
        else if (clickCount == categorySortKey.getClickCount() && orderCount < categorySortKey.getOrderCount()) {
            return true;  // 返回true，表示当前对象小于传入对象
        }
        // 如果点击数和订单数都相等，则比较支付数。如果当前对象的支付数小于传入对象的支付数，则当前对象"小于"传入对象
        else if (clickCount == categorySortKey.getClickCount() && orderCount == categorySortKey.getOrderCount() && payCount < categorySortKey.getPayCount()) {
            return true;  // 返回true，表示当前对象小于传入对象
        }

        // 如果上述条件都不满足，则说明当前对象不小于传入对象，返回false
        return false;
    }


    @Override
    public boolean $greater(CategorySortKey categorySortKey) {
        if(clickCount>categorySortKey.getClickCount())
        {
            return true;
        }else if(clickCount==categorySortKey.getClickCount()&&orderCount>categorySortKey.getOrderCount())
        {
            return true;
        }
        else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount>categorySortKey.getPayCount())
            return true;

        return false;
    }

    @Override
    public boolean $less$eq(CategorySortKey categorySortKey) {
        if($less(categorySortKey))
        {
            return true;
        }
        else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount==categorySortKey.getPayCount())
            return true;
        return false;
    }

    @Override
    public boolean $greater$eq(CategorySortKey categorySortKey) {
        if($greater(categorySortKey))
        {
            return true;
        }else if(clickCount==categorySortKey.getClickCount()&&orderCount==categorySortKey.getOrderCount()&&payCount==categorySortKey.getPayCount())
            return true;
        return false;
    }

    @Override
    public int compareTo(CategorySortKey categorySortKey) {
        if(clickCount-categorySortKey.getClickCount()!=0)
        {
            return (int) (clickCount-categorySortKey.getClickCount());
        }else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()!=0)
        {
            return (int) (orderCount-categorySortKey.getOrderCount());
        }
        else if(clickCount-categorySortKey.getClickCount()==0&&orderCount-categorySortKey.getOrderCount()==0&&payCount-categorySortKey.getPayCount()!=0)
            return (int) (payCount-categorySortKey.getPayCount());
        return 0;
    }

    public Long getClickCount() {
        return clickCount;
    }

    public void setClickCount(Long clickCount) {
        this.clickCount = clickCount;
    }

    public Long getOrderCount() {
        return orderCount;
    }

    public void setOrderCount(Long orderCount) {
        this.orderCount = orderCount;
    }

    public Long getPayCount() {
        return payCount;
    }

    public void setPayCount(Long payCount) {
        this.payCount = payCount;
    }

    public void set(Long clickCount, Long orderCount, Long payCount) {
        this.clickCount = clickCount;
        this.orderCount = orderCount;
        this.payCount = payCount;
    }
}
