package com.cf.imes.module.system.dal.dataobject.user;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;

/**
 * @author Gqr
 * @since 2025/9/30 15:32
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class UserStatusGroupStatisticsDO implements Comparable<UserStatusGroupStatisticsDO> {
    /**
     * 用户数量
     */
    private Integer userCount;

    /**
     * 更新时间格式
     */
    private String date;

    @Override
    public int compareTo(@NotNull UserStatusGroupStatisticsDO o) {
        // 解析 date 字符串为年、月、周
        String[] partsThis = date.split("-");
        String[] partsOther = o.date.split("-");

        // 比较年份
        int yearComparison = Integer.compare(Integer.parseInt(partsThis[0]), Integer.parseInt(partsOther[0]));
        if (yearComparison != 0) {
            return yearComparison;
        }

        // 比较月份
        if (partsThis.length > 1 && partsOther.length > 1) {
            int monthComparison = Integer.compare(Integer.parseInt(partsThis[1]), Integer.parseInt(partsOther[1]));
            if (monthComparison != 0) {
                return monthComparison;
            }
        }

        // 比较周数
        if (partsThis.length > 2 && partsOther.length > 2) {
            int weekComparison = Integer.compare(Integer.parseInt(partsThis[2]), Integer.parseInt(partsOther[2]));
            if (weekComparison != 0) {
                return weekComparison;
            }
        }

        // 如果所有部分都相同，则按状态排序
        return this.userCount.compareTo(o.userCount);
    }
}
