package com.iqser.red.service.persistence.management.v1.processor.service.layoutparsing;

import com.iqser.red.service.persistence.management.v1.processor.model.PyInfraRequest;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileType;

import lombok.experimental.UtilityClass;

@UtilityClass
public class ChunkingRequestFactory {

    private static final String PAGES = "pages";
    private static final String TEXT_BLOCKS = "textBlocks";
    private static final String TEXT_POSITIONS = "positions";
    private static final String STRUCTURE = "structure";


    public PyInfraRequest createChunkingRequest(String dossierId, String fileId, boolean protoFileExists) {

        PyInfraRequest pyInfraRequest = new PyInfraRequest(dossierId, fileId);

        if (protoFileExists) {
            pyInfraRequest.addTargetFilePath(PAGES, FileType.DOCUMENT_PAGES);
            pyInfraRequest.addTargetFilePath(TEXT_BLOCKS, FileType.DOCUMENT_TEXT);
            pyInfraRequest.addTargetFilePath(TEXT_POSITIONS, FileType.DOCUMENT_POSITION);
            pyInfraRequest.addTargetFilePath(STRUCTURE, FileType.DOCUMENT_STRUCTURE);
        } else {
            pyInfraRequest.addTargetFilePath(PAGES, FileType.DOCUMENT_PAGES.name(), FileType.DOCUMENT_PAGES_OLD.getExtension());
            pyInfraRequest.addTargetFilePath(TEXT_BLOCKS, FileType.DOCUMENT_TEXT.name(), FileType.DOCUMENT_TEXT_OLD.getExtension());
            pyInfraRequest.addTargetFilePath(TEXT_POSITIONS, FileType.DOCUMENT_POSITION.name(), FileType.DOCUMENT_POSITION_OLD.getExtension());
            pyInfraRequest.addTargetFilePath(STRUCTURE, FileType.DOCUMENT_STRUCTURE.name(), FileType.DOCUMENT_STRUCTURE_OLD.getExtension());
        }

        pyInfraRequest.setResponseFilePath(FileType.DOCUMENT_CHUNKS);
        return pyInfraRequest;
    }

}
