package com.cf.imes.module.system.api.organ.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import jakarta.validation.constraints.NotNull;

@Schema(description = "管理后台 - 组织是否新增统计")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class OrgStatisticsIsLapseRespDTO implements Comparable<OrgStatisticsIsLapseRespDTO>{

    @Schema(description = "组织状态")
    private Integer orgStatus;

    @Schema(description = "组织数量")
    private Integer orgCount;

    @Schema(description = "组织时间")
    private String date;

    @Schema(description = "是否删除")
    private Boolean deleted;


    @Override
    public int compareTo(@NotNull OrgStatisticsIsLapseRespDTO o) {
        // 解析 orderDate 字符串为年、月、周
        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.orgStatus.compareTo(o.orgStatus);
    }
}
