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 EiamFormSyncResult {

    private String formInstanceId;
    private EiamBatchOperation operation;
    private int total;
    private int successCount;
    private int failedCount;
    private List<EiamBatchItemResult> items;
    private boolean writebackSuccess;
    private String writebackMessage;

    /**
     * 合并批量执行结果和宜搭回写状态。
     *
     * @param formInstanceId 宜搭实例 ID
     * @param batchResult EIAM 批量结果
     * @param writebackSuccess 是否回写成功
     * @param writebackMessage 回写说明
     * @return 同步结果
     */
    public static EiamFormSyncResult of(String formInstanceId, EiamBatchResult batchResult,
                                        boolean writebackSuccess, String writebackMessage) {
        return EiamFormSyncResult.builder()
                .formInstanceId(formInstanceId)
                .operation(batchResult.getOperation())
                .total(batchResult.getTotal())
                .successCount(batchResult.getSuccessCount())
                .failedCount(batchResult.getFailedCount())
                .items(batchResult.getItems())
                .writebackSuccess(writebackSuccess)
                .writebackMessage(writebackMessage)
                .build();
    }
}
