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;

@Schema(description = "管理后台 - 统一取费子目工料机响应 VO")
@Data
public class QuotaUnifiedFeeResourceRespVO {

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

    @Schema(description = "关联子定额ID", example = "1001")
    private Long unifiedFeeSettingId;

    @Schema(description = "关联工料机ID（yhy_resource_item）", example = "2001")
    private Long resourceItemId;

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

    @Schema(description = "调整消耗量", example = "1.8")
    private BigDecimal adjustedDosage;

    // ==================== 关联工料机信息（从yhy_resource_item动态获取，命名与QuotaResourceRespVO保持一致）====================

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

    @Schema(description = "资源名称", example = "普通工")
    private String resourceName;

    @Schema(description = "资源型号规格", example = "标准规格")
    private String resourceSpec;

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

    @Schema(description = "资源单位", example = "工日")
    private String resourceUnit;

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

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

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

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

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

    // ==================== 计算字段（合价 = 单价 × 消耗量）====================

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

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

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

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

    @Schema(description = "扩展属性")
    private Map<String, Object> attributes;

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

    @Schema(description = "排序字段", example = "1")
    private Integer sortOrder;

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

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

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

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

    /**
     * 复合工料机子数据 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 = "源工料机类型", 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 = "1.5")
        private BigDecimal dosage;

        @Schema(description = "计算基数")
        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;
    }
}
