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

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

import java.math.BigDecimal;

@Schema(description = "管理后台 - 按材料统计小板数量")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@ToString(callSuper = true)
public class OrderGoodsPlateRespVO implements Comparable<OrderGoodsPlateRespVO> {

    @Schema(description = "商品 ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "243")
    private String goodsId;

    @Schema(description = "商品名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "晨丰")
    private String goodsName;

    @Schema(description = "材质：颗粒板、欧松板、多层板、生态板、禾香板、密度板、实木、铝蜂窝板、铝塑板", requiredMode = Schema.RequiredMode.REQUIRED)
    private String material;

    @Schema(description = "颜色", requiredMode = Schema.RequiredMode.REQUIRED)
    private String color;

    @Schema(description = "纹路")
    private Boolean texture;

    @Schema(description = "宽度", requiredMode = Schema.RequiredMode.REQUIRED)
    private BigDecimal width;

    @Schema(description = "高度", requiredMode = Schema.RequiredMode.REQUIRED)
    private BigDecimal height;

    @Schema(description = "厚度", requiredMode = Schema.RequiredMode.REQUIRED)
    private BigDecimal thickness;

    @Schema(description = "价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "7305")
    private BigDecimal price;

    @Schema(description = "品牌", requiredMode = Schema.RequiredMode.REQUIRED)
    private String brand;

    @Schema(description = "规格", requiredMode = Schema.RequiredMode.REQUIRED)
    private String spec;

    @Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED, example = "你猜")
    private String remark;

    @Schema(description = "数量")
    private Integer orderCount;

    @Schema(description = "面积")
    private BigDecimal orderArea;

    @Schema(description = "生产单日期")
    private String orderDate;

    @Override
    public int compareTo(@NotNull OrderGoodsPlateRespVO other) {
        if (orderDate != null && other.orderDate != null) {
            // 解析 date 字符串为年、月、周
            String[] partsThis = orderDate.split("-");
            String[] partsOther = other.orderDate.split("-");

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

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

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