package com.yhy.module.core.controller.admin.workbench.vo.price;

import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 定额单价计算结果（含完整调试信息）
 * 
 * 用于定额单价计算的最终结果，包含各层计算的中间结果用于调试
 * 
 * @author yhy
 */
@Schema(description = "工作台 - 定额单价计算结果")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QuotaUnitPriceResult {

    // ========== 最终结果 ==========

    @Schema(description = "定额节点ID", example = "1")
    private Long divisionId;

    @Schema(description = "定额基价ID", example = "1")
    private Long quotaItemId;

    @Schema(description = "定额单价（综合单价）", example = "12.50")
    private BigDecimal unitPrice;

    @Schema(description = "计算是否成功", example = "true")
    private Boolean success;

    @Schema(description = "错误信息（如果计算失败）")
    private String errorMessage;

    // ========== 调试信息（可选返回） ==========

    @Schema(description = "第1层：工料机合价明细")
    private List<ResourcePriceDetail> resourceDetails;

    @Schema(description = "第2层：调整消耗量明细")
    private List<AdjustmentDetail> adjustmentDetails;

    @Schema(description = "第3层：分类汇总（key=categoryId）")
    private Map<Long, CategoryPriceSum> categorySums;

    @Schema(description = "第4-5层：单价构成明细")
    private List<FeeItemPriceResult> feeItemDetails;

    @Schema(description = "计算耗时（毫秒）", example = "45")
    private Long calculateTimeMs;

    /**
     * 创建成功结果
     */
    public static QuotaUnitPriceResult success(Long divisionId, Long quotaItemId, BigDecimal unitPrice) {
        return QuotaUnitPriceResult.builder()
                .divisionId(divisionId)
                .quotaItemId(quotaItemId)
                .unitPrice(unitPrice)
                .success(true)
                .build();
    }

    /**
     * 创建失败结果
     */
    public static QuotaUnitPriceResult fail(Long divisionId, Long quotaItemId, String errorMessage) {
        return QuotaUnitPriceResult.builder()
                .divisionId(divisionId)
                .quotaItemId(quotaItemId)
                .unitPrice(BigDecimal.ZERO)
                .success(false)
                .errorMessage(errorMessage)
                .build();
    }
}
