class LogbookDetailsCheckServiceImpl implements LogbookDetailsCheckService {

    @Override
    public List<LogbookCheckError> checkEvent(EventModel event) {
        List<LogbookCheckError> logbookCheckErrors = new ArrayList<>();

        // check event evType coherence.
        if (LogbookEventType.TASK.equals(event.getLogbookEventType())
            && event.getEvTypeParent() != null) {

            // the evType must have the following format : <evTypeParent.*>
            String evTypeFormat = event.getEvTypeParent() + DOT;
            if (!event.getEvType().startsWith(evTypeFormat)) {
                // construct LogbookCheckResult
                logbookCheckErrors
                    .add(new LogbookCheckError(event.getOperationId(), event.getLfcId(), event.getEvType(),
                        String.format(SAVED_LOGBOOK_MSG, LogbookEventName.EVTYPE.getValue(), event.getEvType()),
                        String.format(EXPECTED_LOGBOOK_MSG, LogbookEventName.EVTYPE.getValue(), evTypeFormat + "*")));
            }
        }

        // check outcome coherence.
        boolean isOutcomeOk = Stream.of(OutcomeStatus.values()).map(String::valueOf)
            .anyMatch(s -> s.contains(event.getOutcome()));

        if (!isOutcomeOk) {
            logbookCheckErrors.add(new LogbookCheckError(event.getOperationId(), event.getLfcId(), event.getEvType(),
                String
                    .format(SAVED_LOGBOOK_MSG, event.getEvType() + " " + LogbookEventName.OUTCOME.getValue(),
                        event.getOutcome()),
                String.format(EXPECTED_LOGBOOK_MSG, LogbookEventName.OUTCOME.getValue()
                    , Stream.of(OutcomeStatus.values()).map(String::valueOf).collect(Collectors.joining(", ")))));
        }

        // Check event outcomeDetails coherence.
        // regex -> outcomeDetails must have the following format : <evType.*.outcome>
        String regex = "^" + event.getEvType() + "(\\.(\\w+))*\\." + event.getOutcome() + "$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(event.getOutDetail());

        if (!matcher.find()) {
            logbookCheckErrors.add(new LogbookCheckError(event.getOperationId(), event.getLfcId(), event.getEvType(),
                String.format(SAVED_LOGBOOK_MSG, LogbookEventName.OUTCOMEDETAILS.getValue(), event.getOutDetail()),
                String.format(EXPECTED_LOGBOOK_MSG, LogbookEventName.OUTCOMEDETAILS.getValue(), regex)));
        }

        return logbookCheckErrors;
    }

}