package com.intrasoft.ermis.transit.officeofdeparture.service;

import com.intrasoft.ermis.common.bpmn.core.BpmnEngine;
import com.intrasoft.ermis.common.bpmn.core.CorrelateBpmnMessageCommand;
import com.intrasoft.ermis.common.logging.ErmisLogger;
import com.intrasoft.ermis.common.xml.parsing.XmlConverter;
import com.intrasoft.ermis.ddntav5152.messages.CC013CType;
import com.intrasoft.ermis.ddntav5152.messages.CC015CType;
import com.intrasoft.ermis.ddntav5152.messages.ConsignmentItemType09;
import com.intrasoft.ermis.ddntav5152.messages.HouseConsignmentType10;
import com.intrasoft.ermis.ddntav5152.messages.MessageTypes;
import com.intrasoft.ermis.transit.common.exceptions.NotFoundException;
import com.intrasoft.ermis.transit.common.transition.period.TransitionPeriodService;
import com.intrasoft.ermis.transit.contracts.core.enums.PreviousDocumentTypeEnum;
import com.intrasoft.ermis.transit.officeofdeparture.domain.Declaration;
import com.intrasoft.ermis.transit.officeofdeparture.domain.DomainBase;
import com.intrasoft.ermis.transit.officeofdeparture.domain.Message;
import com.intrasoft.ermis.transit.officeofdeparture.domain.MessageOverview;
import com.intrasoft.ermis.transit.officeofdeparture.domain.Movement;
import com.intrasoft.ermis.transit.officeofdeparture.domain.MovementAttribute;
import com.intrasoft.ermis.transit.officeofdeparture.domain.WorkTask;
import com.intrasoft.ermis.transit.officeofdeparture.domain.enums.BpmnFlowMessagesEnum;
import com.intrasoft.ermis.transit.officeofdeparture.domain.enums.BpmnFlowVariablesEnum;
import com.intrasoft.ermis.transit.officeofdeparture.domain.enums.MovementAttributesEnum;
import com.intrasoft.ermis.transit.officeofdeparture.domain.enums.ProcessDefinitionEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.xml.bind.JAXBException;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class TransitAfterAESServiceImpl implements TransitAfterAESService {

    private static final String CANCELLATION_REASON = "Amendment invalidated. Invalidation cause: new Amendment received";

    private final ErmisLogger log;

    private final DossierDataService dossierDataService;

    private final BpmnEngine bpmnEngine;

    private final BpmnFlowService bpmnFlowService;

    private final TimerService timerService;

    private final TransitionPeriodService transitionPeriodService;

    private final WorkTaskManagerDataService workTaskManagerDataService;

    @Override
    public boolean isTransitSAfterAES(String movementId) throws JAXBException {
        Declaration declaration = dossierDataService.getLatestDeclarationByMovementId(movementId);
        CC015CType cc015cTypeMessage = XmlConverter.buildMessageFromXML(declaration.getPayload(), CC015CType.class);
        return doIsTransitSAfterAES(cc015cTypeMessage);
    }

    @Override
    @SneakyThrows
    public boolean isTransitSAfterAESAndIsAESNCTSEnabled(String movementId) {
        return isTransitSAfterAES(movementId) && isAESNCTSEnabled(movementId);
    }

    @Override
    public boolean isAESNCTSEnabled(String movementId) {
        MovementAttribute movementAttribute = dossierDataService.findMovementAttributeByMovementIdAndAttrKey(movementId,
                MovementAttributesEnum.AES_COMMUNICATION_ENABLED.getValue());

        if (movementAttribute != null) {
            return Boolean.parseBoolean(movementAttribute.getAttrValue());
        }

        //default should be false
        return false;
    }

    @Override
    public void cancelAllOpenWorkTasks(String movementId) {
        // Find any OPEN work tasks in database and change their status to 'CANCELLED'.
        List<WorkTask> openWorkTaskList =
                new ArrayList<>(workTaskManagerDataService.findOpenWorkTasksByMovementId(movementId));

        openWorkTaskList.forEach(workTask -> workTaskManagerDataService.autoUpdateWorkTask(workTask.getWorkTaskId()));
    }

    @Override
    public boolean arePreviousDocumentMRNsSame(String movementId) throws JAXBException {
        List<String> refNumbersFrom015 = getListWithPreviousDocumentMRNsOf015(movementId);
        List<String> refNumbersFrom013 = getListWithPreviousDocumentMRNsOf013(movementId);
        if (refNumbersFrom015.size() != refNumbersFrom013.size()) {
            return false;
        } else {
            return refNumbersFrom015.equals(refNumbersFrom013);
        }
    }

    private List<String> getListWithPreviousDocumentMRNsOf015(String movementId) throws JAXBException {
        List<String> previousDocumentMRNs = new ArrayList<>();
        Declaration cc015c = dossierDataService.getLatestDeclarationByMovementId(movementId);
        if (cc015c != null && cc015c.getPayload() != null) {
            CC015CType cc015CType = XmlConverter.buildMessageFromXML(cc015c.getPayload(), CC015CType.class);
            //CI lvl
            cc015CType.getConsignment().getHouseConsignment()
                      .forEach(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem()
                                                                               .forEach(consignmentItemType09 -> consignmentItemType09.getPreviousDocument()
                                                                                                                                      .stream()
                                                                                                                                      .filter(previousDocumentType08 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                                                                                                                                              .equals(previousDocumentType08.getType()))
                                                                                                                                      .forEach(
                                                                                                                                              previousDocumentType08 -> previousDocumentMRNs.add(
                                                                                                                                                      previousDocumentType08.getReferenceNumber()))));
            //HC lvl
            cc015CType.getConsignment()
                      .getHouseConsignment()
                      .forEach(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument()
                                                                               .stream()
                                                                               .filter(previousDocumentType10 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                                                                                       .equals(previousDocumentType10.getType()))
                                                                               .forEach(previousDocumentType10 -> previousDocumentMRNs.add(
                                                                                       previousDocumentType10.getReferenceNumber())));
            //HC lvl
            cc015CType.getConsignment().getPreviousDocument().stream()
                      .filter(previousDocumentType09 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                              .equals(previousDocumentType09.getType()))
                      .forEach(previousDocumentType09 -> previousDocumentMRNs.add(previousDocumentType09.getReferenceNumber()));

        }
        Collections.sort(previousDocumentMRNs);
        return previousDocumentMRNs;
    }

    private List<String> getListWithPreviousDocumentMRNsOf013(String movementId) throws JAXBException {
        List<String> previousDocumentMRNs = new ArrayList<>();
        List<MessageOverview> messageOverviewList = dossierDataService.getMessagesOverview(movementId, MessageTypes.CC_013_C.value());
        if (!messageOverviewList.isEmpty()) {
            messageOverviewList.sort(Comparator.comparing(DomainBase::getCreatedDateTime));
            MessageOverview messageOverview = messageOverviewList.get(messageOverviewList.size() - 1);
            String messageId = messageOverview.getId();
            Message cc013cMessage = dossierDataService.getMessageById(messageId);
            if (cc013cMessage != null) {
                CC013CType cc013CType = XmlConverter.buildMessageFromXML(cc013cMessage.getPayload(), CC013CType.class);
                //CI lvl
                cc013CType.getConsignment().getHouseConsignment()
                          .forEach(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem()
                                                                                   .forEach(consignmentItemType09 -> consignmentItemType09.getPreviousDocument()
                                                                                                                                          .stream()
                                                                                                                                          .filter(previousDocumentType08 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                                                                                                                                                  .equals(previousDocumentType08.getType()))
                                                                                                                                          .forEach(
                                                                                                                                                  previousDocumentType08 -> previousDocumentMRNs.add(
                                                                                                                                                          previousDocumentType08.getReferenceNumber()))));
                //HC lvl
                cc013CType.getConsignment()
                          .getHouseConsignment()
                          .forEach(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument()
                                                                                   .stream()
                                                                                   .filter(previousDocumentType10 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                                                                                           .equals(previousDocumentType10.getType()))
                                                                                   .forEach(previousDocumentType10 -> previousDocumentMRNs.add(
                                                                                           previousDocumentType10.getReferenceNumber())));
                //HC lvl
                cc013CType.getConsignment().getPreviousDocument().stream()
                          .filter(previousDocumentType09 -> PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                                  .equals(previousDocumentType09.getType()))
                          .forEach(previousDocumentType09 -> previousDocumentMRNs.add(previousDocumentType09.getReferenceNumber()));

            }
        }
        Collections.sort(previousDocumentMRNs);
        return previousDocumentMRNs;
    }

    private boolean doIsTransitSAfterAES(CC015CType cc015CType) {

        boolean b = cc015CType.getConsignment()
                              .getHouseConsignment()
                              .stream()
                              .map(HouseConsignmentType10::getPreviousDocument)
                              .flatMap(List::stream)
                              .anyMatch(x -> x.getType().equals(PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()));

        // Check in HS -> CI -> previous document lvl ONLY if we are in TP
        if (transitionPeriodService.isNowNCTSTransitionPeriod()) {
            return b || cc015CType.getConsignment()
                                  .getHouseConsignment()
                                  .stream()
                                  .map(HouseConsignmentType10::getConsignmentItem)
                                  .flatMap(List::stream)
                                  .map(ConsignmentItemType09::getPreviousDocument)
                                  .flatMap(List::stream)
                                  .anyMatch(x -> x.getType().equals(PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()));
        }

        return b;
    }

    @Override
    public boolean isCC13CTransitSAfterAES(String messageId, String movementId) throws JAXBException {
        Message cc013cMessage = dossierDataService.getMessageById(messageId);
        boolean isTransitSAfterAES = false;
        if (cc013cMessage != null) {
            CC013CType cc013CType = XmlConverter.buildMessageFromXML(cc013cMessage.getPayload(), CC013CType.class);

            if (cc013CType.getConsignment() != null && !CollectionUtils.isEmpty(cc013CType.getConsignment().getHouseConsignment())) {
                isTransitSAfterAES = cc013CType.getConsignment()
                                               .getHouseConsignment()
                                               .stream()
                                               .flatMap(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument()
                                                                                                        .stream())
                                               .anyMatch(previousDocumentType04 ->
                                                       PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                             .equals(previousDocumentType04.getType()))
                        || cc013CType.getConsignment()
                                     .getHouseConsignment()
                                     .stream()
                                     .flatMap(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem().stream())
                                     .flatMap(consignmentItemType09 -> consignmentItemType09.getPreviousDocument()
                                                                                            .stream())
                                     .anyMatch(previousDocumentType08 ->
                                             PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue()
                                                                                                   .equals(previousDocumentType08.getType()));


                log.info("isTransitSAfterAES {}", isTransitSAfterAES);
            }
        }

        return isTransitSAfterAES;
    }


    @Override
    public boolean isCC013CTransitAfterAes(String movementId) throws JAXBException {
        boolean cc013cIsTransitAfterAes = false;
        List<MessageOverview> messageOverviewList = dossierDataService.getMessagesOverview(movementId, MessageTypes.CC_013_C.value());
        if (!messageOverviewList.isEmpty()) {
            messageOverviewList.sort(Comparator.comparing(DomainBase::getCreatedDateTime));
            MessageOverview messageOverview = messageOverviewList.get(messageOverviewList.size() - 1);
            String messageId = messageOverview.getId();
            cc013cIsTransitAfterAes = isCC13CTransitSAfterAES(messageId, movementId);
        }
        return cc013cIsTransitAfterAes;
    }

    @Override
    public void initNegativeIE191Flow(String movementId, String messageId) {
        final CorrelateBpmnMessageCommand correlateBpmnMessageCommand = CorrelateBpmnMessageCommand
                .builder()
                .businessKey(movementId)
                .messageName(BpmnFlowMessagesEnum.INIT_FLOW_FOR_NEGATIVE_IE191.getTypeValue())
                .value(BpmnFlowVariablesEnum.PROCESS_BUSINESS_KEY.getTypeValue(), movementId)
                .value(BpmnFlowVariablesEnum.WAITING_AMENDMENT_TIMER_DELAY.getTypeValue(),
                        timerService.getAmendmentExpirationTimerDelayConfig().getTimerSetupString())
                .value(BpmnFlowVariablesEnum.MOVEMENT_ID.getTypeValue(), movementId)
                .build();
        bpmnEngine.correlateMessage(correlateBpmnMessageCommand);
    }

    @Override
    public void cancelPreviousAmendmentProcess(String movementId) {
        List<MessageOverview> messageOverview = dossierDataService.getMessagesOverview(movementId, MessageTypes.CC_013_C.value()); //get all 013s
        if (!messageOverview.isEmpty()) {
            Movement movement = dossierDataService.getMovementById(movementId);
            messageOverview.sort(Comparator.comparing(DomainBase::getCreatedDateTime));
            if (movement == null) {
                throw new NotFoundException("No movement found for movement id".concat(movementId));
            }
            MessageOverview previousO13Message = messageOverview.get(messageOverview.size() - 2);
            final String cancellationReason = createCancellationReason();
            bpmnFlowService.cancelProcessInstanceIfExists(movementId.concat("-").concat(previousO13Message.getId()),
                    ProcessDefinitionEnum.OODEPARTURE_HANDLE_AMENDMENT_REQUEST_PROCESS.getProcessDefinitionKey(),
                    cancellationReason);
        }

    }

    private String createCancellationReason() {
        return CANCELLATION_REASON;
    }
}

package com.intrasoft.ermis.trs.officeofdeparture.service;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.when;

import com.intrasoft.ermis.common.xml.parsing.XmlConverter;
import com.intrasoft.ermis.ddntav5152.messages.CC015CType;
import com.intrasoft.ermis.ddntav5152.messages.MessageTypes;
import com.intrasoft.ermis.ddntav5152.messages.PreviousDocumentType10;
import com.intrasoft.ermis.transit.common.transition.period.TransitionPeriodService;
import com.intrasoft.ermis.transit.contracts.core.enums.PreviousDocumentTypeEnum;
import com.intrasoft.ermis.trs.officeofdeparture.util.GeneratorHelper;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.xml.bind.JAXBException;
import org.junit.jupiter.api.Named;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;


@ExtendWith(MockitoExtension.class)
class TransitAfterAESServiceUT extends GeneratorHelper {

    private static final String FILENAME = "CC015C_AES";

    @Mock
    private TransitionPeriodService transitionPeriodService;

    private CC015CType cc015CType;

    @Test
    void testCommunicationWithAESNeeded() throws JAXBException {

        when(dossierDataService.getLatestDeclarationByMovementId(MOVEMENT_ID)).thenReturn(createDeclaration(MessageTypes.CC_015_C.value(), FILENAME));

        boolean communicationWithAESNeeded = !transitAfterAESService.arePreviousDocumentMRNsSame(MOVEMENT_ID);
        assertTrue(communicationWithAESNeeded);
    }

    @ParameterizedTest
    @MethodSource("namedArguments")
    void test_IsTransitAfterAESDuringTP(String previousDocumentLevel) {

        try {
            cc015CType = XmlConverter.buildMessageFromXML(loadTextFile(FILENAME), CC015CType.class);

            if ("houseConsignment".equals(previousDocumentLevel)) {
                alterMessagePreviousDocumentLevel(cc015CType);
            }

            when(dossierDataService.getLatestDeclarationByMovementId(MOVEMENT_ID)).thenReturn(createDeclaration(MessageTypes.CC_015_C.value(), FILENAME));
            Mockito.when(transitionPeriodService.isNowNCTSTransitionPeriod()).thenReturn(true);

            boolean result = transitAfterAESService.isTransitSAfterAES(MOVEMENT_ID);
            assertTrue(result);

            if ("houseConsignment".equals(previousDocumentLevel)) {
                assertionsForPreviousDocumentInHC();
            } else {
                assertionsForPreviousDocumentInCI();
            }
        } catch (JAXBException e) {
            fail();
        }
    }

    @Test
    void test_IsTransitAfterAESAfterTP() {

        try {
            cc015CType = XmlConverter.buildMessageFromXML(loadTextFile(FILENAME), CC015CType.class);

            alterMessagePreviousDocumentLevel(cc015CType);

            when(dossierDataService.getLatestDeclarationByMovementId(MOVEMENT_ID)).thenReturn(createDeclaration(cc015CType));
            Mockito.when(transitionPeriodService.isNowNCTSTransitionPeriod()).thenReturn(false);

            boolean result = transitAfterAESService.isTransitSAfterAES(MOVEMENT_ID);
            assertTrue(result);

            assertionsForPreviousDocumentInHC();
        } catch (JAXBException e) {
            fail();
        }
    }

    @Test
    void test_IsNotTransitAfterAESDuringTP() {

        try {
            cc015CType = XmlConverter.buildMessageFromXML(loadTextFile(FILENAME), CC015CType.class);

            removePreviousDocumentsFromCI(cc015CType);

            when(dossierDataService.getLatestDeclarationByMovementId(MOVEMENT_ID)).thenReturn(createDeclaration(cc015CType));
            Mockito.when(transitionPeriodService.isNowNCTSTransitionPeriod()).thenReturn(true);

            boolean result = transitAfterAESService.isTransitSAfterAES(MOVEMENT_ID);
            assertFalse(result);

            assertionsForNoPreviousDocument();
        } catch (JAXBException e) {
            fail();
        }
    }

    @ParameterizedTest
    @MethodSource("namedArguments2")
    void test_IsNotTransitAfterAESAfterTP(String previousDocumentLevel) {

        try {
            cc015CType = XmlConverter.buildMessageFromXML(loadTextFile(FILENAME), CC015CType.class);

            if ("none".equals(previousDocumentLevel)) {
                removePreviousDocumentsFromCI(cc015CType);
            }

            when(dossierDataService.getLatestDeclarationByMovementId(MOVEMENT_ID)).thenReturn(createDeclaration(cc015CType));
            Mockito.when(transitionPeriodService.isNowNCTSTransitionPeriod()).thenReturn(false);

            boolean result = transitAfterAESService.isTransitSAfterAES(MOVEMENT_ID);
            assertFalse(result);

            if ("consignmentItem".equals(previousDocumentLevel)) {
                assertionsForPreviousDocumentInCI();
            } else {
                assertionsForNoPreviousDocument();
            }
        } catch (JAXBException e) {
            fail();
        }
    }


    static Stream<Arguments> namedArguments() {
        return Stream.of(
                Arguments.of(Named.of(" previousDocument in HC", "houseConsignment")),
                Arguments.of(Named.of(" previousDocument in CI", "consignmentItem"))
        );
    }

    static Stream<Arguments> namedArguments2() {
        return Stream.of(
                Arguments.of(Named.of(" no previousDocument in any level", "none")),
                Arguments.of(Named.of(" previousDocument in CI", "consignmentItem"))
        );
    }

    private void alterMessagePreviousDocumentLevel(CC015CType cc015CType) {
        removePreviousDocumentsFromCI(cc015CType);
        addPreviousDocumentInHC(cc015CType);
    }

    private void removePreviousDocumentsFromCI(CC015CType cc015CType) {
        cc015CType.getConsignment()
                  .getHouseConsignment()
                  .stream()
                  .flatMap(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem().stream())
                  .forEach(consignmentItemType09 -> consignmentItemType09.getPreviousDocument().clear());
    }

    private void addPreviousDocumentInHC(CC015CType cc015CType) {
        PreviousDocumentType10 previousDocumentType10 = new PreviousDocumentType10();
        previousDocumentType10.setType("N830");
        previousDocumentType10.setSequenceNumber("1");
        previousDocumentType10.setReferenceNumber("23DK11111111111111");

        cc015CType.getConsignment().getHouseConsignment().get(0).getPreviousDocument().add(previousDocumentType10);
    }

    private void assertionsForNoPreviousDocument() {
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument().stream())
                             .noneMatch(previousDocumentType10 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType10.getType())));
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem().stream())
                             .flatMap(consignmentItemType09 -> consignmentItemType09.getPreviousDocument().stream())
                             .toList()
                             .stream()
                             .noneMatch(previousDocumentType08 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType08.getType())));
    }

    private void assertionsForPreviousDocumentInCI() {
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument().stream())
                             .noneMatch(previousDocumentType10 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType10.getType())));
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem().stream())
                             .flatMap(consignmentItemType09 -> consignmentItemType09.getPreviousDocument().stream())
                             .toList()
                             .stream()
                             .anyMatch(previousDocumentType08 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType08.getType())));
    }

    private void assertionsForPreviousDocumentInHC() {
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getPreviousDocument().stream())
                             .anyMatch(previousDocumentType10 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType10.getType())));
        assertTrue(cc015CType.getConsignment().getHouseConsignment().stream()
                             .flatMap(houseConsignmentType10 -> houseConsignmentType10.getConsignmentItem().stream())
                             .flatMap(consignmentItemType09 -> consignmentItemType09.getPreviousDocument().stream())
                             .toList()
                             .stream()
                             .noneMatch(previousDocumentType08 ->
                                     PreviousDocumentTypeEnum.GOODS_EXPORTATION_DECLARATION.getValue().equals(previousDocumentType08.getType())));
    }
}
