package com.workfusion.odf.service;

import java.util.List;
import java.util.function.Predicate;

import com.workfusion.odf.api.domain.Document;

/**
 * Join-Split orchestrator, providing high-level interface for splitting transaction into individual documents for
 * separate proessing and joining them back into same transaction.
 */
public interface SplitJoinService {

    /**
     * Splits all documents for further processing.
     *
     * @param transactionId target transaction id to be split
     * @return list of documents for processing
     */
    List<Document> splitTransaction(String transactionId);

    /**
     * Splits all documents matching the criteria for further processing.
     *
     * @param transactionId target transaction id to be split
     * @param documentFilter documents for to be split
     * @return list of documents for processing
     */
    List<Document> splitTransaction(String transactionId, Predicate<Document> documentFilter);

    /**
     * Splits all documents for further OCR processing. Picks documents matching Document#isOcrDocument criteria
     *
     * @param transactionId target transaction id to be split
     * @return list of documents for processing
     */
    List<Document> splitTransactionForOCR(String transactionId);

    /**
     * Join a single document back into transaction. If this is the last document then method will return true value.
     *
     * @param transactionId Parent transaction id where document should be joined
     * @param documentId document id to be joined
     * @return true if all documents were joined, else false
     */
    boolean joinTransaction(String transactionId, String documentId);

}
