class IdpSelector {

    public static IdpSelectedState buildIdpSelectedState(IdpSelectingState state,
                                                         String idpEntityId,
                                                         boolean registering,
                                                         LevelOfAssurance requestedLoa,
                                                         TransactionsConfigProxy transactionsConfigProxy,
                                                         IdentityProvidersConfigProxy identityProvidersConfigProxy) {

        List<LevelOfAssurance> levelsOfAssuranceForTransaction = transactionsConfigProxy.getLevelsOfAssurance(state.getRequestIssuerEntityId());
        if (!levelsOfAssuranceForTransaction.contains(requestedLoa)) {
            throw StateProcessingValidationException.requestedLevelOfAssuranceUnsupportedByTransactionEntity(state.getRequestIssuerEntityId(), levelsOfAssuranceForTransaction, requestedLoa);
        }

        List<String> availableIdentityProviderEntityIdsForLoa = identityProvidersConfigProxy.getEnabledIdentityProvidersForAuthenticationRequestGeneration(
                state.getRequestIssuerEntityId(), registering, requestedLoa);

        checkValidIdentityProvider(idpEntityId, availableIdentityProviderEntityIdsForLoa, state);

        IdpConfigDto idpConfig = identityProvidersConfigProxy.getIdpConfig(idpEntityId);
        final List<LevelOfAssurance> idpLevelsOfAssurance = idpConfig.getSupportedLevelsOfAssurance();

        boolean idpEnabledForRegistration = identityProvidersConfigProxy.isIDPEnabledForRegistration(
                idpEntityId,
                state.getRequestIssuerEntityId(),
                requestedLoa);

        List<LevelOfAssurance> levelsOfAssuranceForTransactionSupportedByIdp =
                getLevelsOfAssuranceForTransactionSupportedByIdp(
                        idpEnabledForRegistration,
                        idpLevelsOfAssurance,
                        levelsOfAssuranceForTransaction);

        return new IdpSelectedState(
                state.getRequestId(),
                idpEntityId,
                levelsOfAssuranceForTransactionSupportedByIdp,
                idpConfig.getUseExactComparisonType(),
                state.getForceAuthentication().orElse(null),
                state.getAssertionConsumerServiceUri(),
                state.getRequestIssuerEntityId(),
                state.getRelayState().orElse(null),
                state.getSessionExpiryTimestamp(),
                registering,
                requestedLoa,
                state.getSessionId(),
                availableIdentityProviderEntityIdsForLoa,
                state.getTransactionSupportsEidas());
    }

    private  IdpSelector();

}