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

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

/**
 * 分类价格汇总（按机类统计）
 * 
 * 用于定额单价计算中的第3层：按机类分类汇总子目工料机合价
 * 
 * @author yhy
 */
@Schema(description = "工作台 - 分类价格汇总")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CategoryPriceSum {

    @Schema(description = "机类ID", example = "1")
    private Long categoryId;

    @Schema(description = "机类代码", example = "人")
    private String categoryCode;

    @Schema(description = "机类名称", example = "人工")
    private String categoryName;

    @Schema(description = "除税基价合价", example = "1000.00")
    private BigDecimal taxExclBaseSum;

    @Schema(description = "含税基价合价", example = "1130.00")
    private BigDecimal taxInclBaseSum;

    @Schema(description = "除税编制价合价", example = "1050.00")
    private BigDecimal taxExclCompileSum;

    @Schema(description = "含税编制价合价", example = "1186.50")
    private BigDecimal taxInclCompileSum;

    /**
     * 构造函数（仅categoryId）
     */
    public CategoryPriceSum(Long categoryId) {
        this.categoryId = categoryId;
        this.taxExclBaseSum = BigDecimal.ZERO;
        this.taxInclBaseSum = BigDecimal.ZERO;
        this.taxExclCompileSum = BigDecimal.ZERO;
        this.taxInclCompileSum = BigDecimal.ZERO;
    }

    /**
     * 累加除税基价合价
     */
    public void addTaxExclBaseSum(BigDecimal value) {
        if (value != null) {
            this.taxExclBaseSum = this.taxExclBaseSum.add(value);
        }
    }

    /**
     * 累加含税基价合价
     */
    public void addTaxInclBaseSum(BigDecimal value) {
        if (value != null) {
            this.taxInclBaseSum = this.taxInclBaseSum.add(value);
        }
    }

    /**
     * 累加除税编制价合价
     */
    public void addTaxExclCompileSum(BigDecimal value) {
        if (value != null) {
            this.taxExclCompileSum = this.taxExclCompileSum.add(value);
        }
    }

    /**
     * 累加含税编制价合价
     */
    public void addTaxInclCompileSum(BigDecimal value) {
        if (value != null) {
            this.taxInclCompileSum = this.taxInclCompileSum.add(value);
        }
    }

    /**
     * 根据价格字段类型获取对应的合价
     * 
     * @param priceField 价格字段类型
     * @return 对应的合价值
     */
    public BigDecimal getPriceByField(String priceField) {
        if (priceField == null) {
            return BigDecimal.ZERO;
        }
        switch (priceField) {
            case "tax_excl_base_price":
                return taxExclBaseSum != null ? taxExclBaseSum : BigDecimal.ZERO;
            case "tax_incl_base_price":
                return taxInclBaseSum != null ? taxInclBaseSum : BigDecimal.ZERO;
            case "tax_excl_compile_price":
                return taxExclCompileSum != null ? taxExclCompileSum : BigDecimal.ZERO;
            case "tax_incl_compile_price":
                return taxInclCompileSum != null ? taxInclCompileSum : BigDecimal.ZERO;
            default:
                return BigDecimal.ZERO;
        }
    }
}
