package com.malk.benteler.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

/**
 * 宜搭可逐条回写的 EIAM 批量结果。
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class EiamBatchResult {

    private EiamBatchOperation operation;
    private int total;
    private int successCount;
    private int failedCount;
    private List<EiamBatchItemResult> items;

    /**
     * 按明细列表生成批次统计。
     *
     * @param operation 操作类型
     * @param items 逐条结果
     * @return 批量结果
     */
    public static EiamBatchResult of(EiamBatchOperation operation,
                                     List<EiamBatchItemResult> items) {
        int successCount = (int) items.stream().filter(EiamBatchItemResult::isSuccess).count();
        return EiamBatchResult.builder()
                .operation(operation)
                .total(items.size())
                .successCount(successCount)
                .failedCount(items.size() - successCount)
                .items(items)
                .build();
    }
}
