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

import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.rules.DroolsValidationResponse;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.rules.RuleBlacklistErrorMessage;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.rules.RuleSyntaxErrorMessage;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.rules.RuleSyntaxWarningMessage;
import com.iqser.red.service.redaction.v1.model.DroolsValidation;

public class RulesValidationMapper {

    public static DroolsValidationResponse createFromDroolsValidation(DroolsValidation droolsValidation) {

        return DroolsValidationResponse.builder()
                .syntaxErrorMessages(droolsValidation.getSyntaxErrorMessages()
                                             .stream()
                                             .map(droolsSyntaxErrorMessage -> new RuleSyntaxErrorMessage(droolsSyntaxErrorMessage.getLine(),
                                                                                                         droolsSyntaxErrorMessage.getColumn(),
                                                                                                         droolsSyntaxErrorMessage.getMessage()))
                                             .toList())
                .deprecatedWarnings(droolsValidation.getDeprecatedWarnings()
                                            .stream()
                                            .map(droolsSyntaxDeprecatedWarnings -> new RuleSyntaxWarningMessage(droolsSyntaxDeprecatedWarnings.getLine(),
                                                                                                                droolsSyntaxDeprecatedWarnings.getColumn(),
                                                                                                                droolsSyntaxDeprecatedWarnings.getMessage()))
                                            .toList())
                .blacklistErrorMessages(droolsValidation.getBlacklistErrorMessages()
                                                .stream()
                                                .map(droolsBlacklistErrorMessage -> new RuleBlacklistErrorMessage(droolsBlacklistErrorMessage.getLine(),
                                                                                                                  droolsBlacklistErrorMessage.getColumn(),
                                                                                                                  droolsBlacklistErrorMessage.getMessage()))
                                                .toList()).build();
    }

}
