package com.yhy.module.core.controller.admin.quota.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import lombok.Data;

/**
 * 定额工料机组成 Response VO
 * 
 * @author yhy
 */
@Schema(description = "管理后台 - 定额工料机组成 Response VO")
@Data
public class QuotaResourceRespVO {

    @Schema(description = "主键ID", example = "1")
    private Long id;

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

    @Schema(description = "资源项ID", example = "1")
    private Long resourceItemId;

    @Schema(description = "定额消耗量", example = "350.00")
    private BigDecimal dosage;

    @Schema(description = "调整消耗量（应用调整设置后的消耗量）", example = "700.00")
    private BigDecimal adjustedDosage;

    @Schema(description = "扩展属性", example = "{\"loss_rate\":0.02}")
    private Map<String, Object> attributes;

    @Schema(description = "创建时间")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    private LocalDateTime updateTime;

    // ========== 扩展字段 ==========

    @Schema(description = "损耗率", example = "0.02")
    private BigDecimal lossRate;

    @Schema(description = "价格快照", example = "50.00")
    private BigDecimal price;

    @Schema(description = "资源编码快照", example = "R001")
    private String resourceCode;

    @Schema(description = "资源名称快照", example = "水泥")
    private String resourceName;

    @Schema(description = "资源单位快照", example = "kg")
    private String resourceUnit;

    @Schema(description = "资源型号规格快照", example = "P.O 42.5")
    private String resourceSpec;

    @Schema(description = "资源类别ID", example = "1")
    private Long resourceCategoryId;

    @Schema(description = "资源类型", example = "material")
    private String resourceType;

    @Schema(description = "税率", example = "0.13")
    private BigDecimal resourceTaxRate;

    @Schema(description = "除税基价", example = "450.00")
    private BigDecimal resourceTaxExclBasePrice;

    @Schema(description = "含税基价", example = "508.50")
    private BigDecimal resourceTaxInclBasePrice;

    @Schema(description = "除税编制价", example = "460.00")
    private BigDecimal resourceTaxExclCompilePrice;

    @Schema(description = "含税编制价", example = "519.80")
    private BigDecimal resourceTaxInclCompilePrice;

    @Schema(description = "计算基数", example = "{\"formula\":\"人机 + 材\",\"variables\":{\"人机\":2,\"材\":3}}")
    private Map<String, Object> calcBase;

    @Schema(description = "实际消耗量（含损耗）", example = "357.00")
    private BigDecimal actualDosage;

    @Schema(description = "金额", example = "17850.00")
    private BigDecimal amount;

    @Schema(description = "是否复合工料机", example = "false")
    private Boolean isMerged;

    @Schema(description = "复合工料机子数据列表")
    private List<MergedResourceItemVO> mergedItems;

    // ========== 虚拟字段（复合工料机合价） ==========

    @Schema(description = "除税基价合价（虚拟字段，仅复合工料机）", example = "50.00")
    private BigDecimal taxExclBaseTotalSum;

    @Schema(description = "含税基价合价（虚拟字段，仅复合工料机）", example = "54.50")
    private BigDecimal taxInclBaseTotalSum;

    @Schema(description = "除税编制价合价（虚拟字段，仅复合工料机）", example = "55.00")
    private BigDecimal taxExclCompileTotalSum;

    @Schema(description = "含税编制价合价（虚拟字段，仅复合工料机）", example = "59.95")
    private BigDecimal taxInclCompileTotalSum;

    @Schema(description = "调整公式（虚拟字段，显示当前应用的定额调整设置计算公式）", example = "M×1+5=2")
    private String adjustmentFormula;

    /**
     * 复合工料机子数据 VO
     */
    @Schema(description = "复合工料机子数据")
    @Data
    public static class MergedResourceItemVO {
        @Schema(description = "子数据ID", example = "1")
        private Long id;

        @Schema(description = "源工料机ID", example = "100")
        private Long resourceItemId;

        @Schema(description = "源工料机编码", example = "C001")
        private String resourceCode;

        @Schema(description = "源工料机名称", example = "水泥")
        private String resourceName;

        @Schema(description = "源工料机单位", example = "t")
        private String resourceUnit;

        @Schema(description = "源工料机型号规格", example = "P.O 42.5")
        private String resourceSpec;

        @Schema(description = "源工料机类别ID", example = "1")
        private Long resourceCategoryId;

        @Schema(description = "源工料机类型", example = "material")
        private String resourceType;

        @Schema(description = "税率", example = "0.13")
        private BigDecimal resourceTaxRate;

        @Schema(description = "除税基价", example = "100.00")
        private BigDecimal resourceTaxExclBasePrice;

        @Schema(description = "含税基价", example = "113.00")
        private BigDecimal resourceTaxInclBasePrice;

        @Schema(description = "除税编制价", example = "120.00")
        private BigDecimal resourceTaxExclCompilePrice;

        @Schema(description = "含税编制价", example = "135.60")
        private BigDecimal resourceTaxInclCompilePrice;

        @Schema(description = "地区代码", example = "GD")
        private String regionCode;

        @Schema(description = "定额消耗量", example = "1.5")
        private BigDecimal dosage;

        @Schema(description = "除税市场价", example = "450.00")
        private BigDecimal price;

        @Schema(description = "实际消耗量（含损耗）", example = "1.53")
        private BigDecimal actualDosage;

        @Schema(description = "金额", example = "688.50")
        private BigDecimal amount;

        @Schema(description = "计算基数", example = "{\"formula\":\"人机 + 材\",\"variables\":{\"人机\":2,\"材\":3}}")
        private Map<String, Object> calcBase;

        // ========== 虚拟字段（子工料机合价） ==========

        @Schema(description = "除税基价合价（虚拟字段）", example = "50.00")
        private BigDecimal taxExclBaseTotalSum;

        @Schema(description = "含税基价合价（虚拟字段）", example = "54.50")
        private BigDecimal taxInclBaseTotalSum;

        @Schema(description = "除税编制价合价（虚拟字段）", example = "55.00")
        private BigDecimal taxExclCompileTotalSum;

        @Schema(description = "含税编制价合价（虚拟字段）", example = "59.95")
        private BigDecimal taxInclCompileTotalSum;
    }
}
