class AuthnResponseFromCountryService {

    public ResponseAction receiveAuthnResponseFromCountry(SessionId sessionId,
                                                          SamlAuthnResponseContainerDto responseFromCountry) {

        if (sessionRepository.sessionExists(sessionId) && sessionRepository.isSessionInState(sessionId, EidasAuthnFailedErrorState.class)) {
            return nonSuccessResponse(sessionId);
        }

        EidasCountrySelectedStateController stateController = (EidasCountrySelectedStateController) sessionRepository.getStateController(sessionId, EidasCountrySelectedState.class);
        validateCountryIsIn(countriesService.getCountries(sessionId), stateController.getCountryEntityId());

        boolean matchingJourney = stateController.isMatchingJourney();
        String entityToEncryptFor = matchingJourney ? stateController.getMatchingServiceEntityId() : stateController.getRequestIssuerId();

        SamlAuthnResponseTranslatorDto responseToTranslate = samlAuthnResponseTranslatorDtoFactory.fromSamlAuthnResponseContainerDto(responseFromCountry, entityToEncryptFor);
        InboundResponseFromCountry translatedResponse = samlEngineProxy.translateAuthnResponseFromCountry(responseToTranslate);

        return handleResponseFromCountry(translatedResponse, responseFromCountry, sessionId, matchingJourney, stateController);
    }

    @Inject public  AuthnResponseFromCountryService(SamlEngineProxy samlEngineProxy,
                                           SamlSoapProxyProxy samlSoapProxyProxy,
                                           SessionRepository sessionRepository,
                                           SamlAuthnResponseTranslatorDtoFactory samlAuthnResponseTranslatorDtoFactory,
                                           CountriesService countriesService);

}