package com.cf.imes.module.executor.controller.admin.order.vo.order;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;

import java.math.BigDecimal;

@Schema(description = "管理后台 - 生产单平方数统计")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class OrderStatisticsAreaRespVO implements Comparable<OrderStatisticsAreaRespVO> {
    @Schema(description = "订单平方数")
    private BigDecimal areaSum;

    @Schema(description = "生产单时间")
    private String date;

    @Override
    public int compareTo(@NotNull OrderStatisticsAreaRespVO other) {
        // 解析 orderDate 字符串为年、月、周
        String[] partsThis = date.split("-");
        String[] partsOther = other.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.areaSum.compareTo(other.areaSum);
    }
}
