@Override
    public AppResponse process(Flow flow, ActivateAppRequest body) {
        String decodedPin = ChallengeService.decodeMaskedPin(appSession.getIv(), appAuthenticator.getSymmetricKey(), body.getMaskedPincode());
        if ((decodedPin == null || !Pattern.compile("\\d{5}").matcher(decodedPin).matches())) {
            return flow.setFailedStateAndReturnNOK(appSession);
        }
        else if (!appAuthenticator.getUserAppId().equals(body.getUserAppId())){
            digidClient.remoteLog("754", Map.of(lowerUnderscore(ACCOUNT_ID) ,appAuthenticator.getAccountId()));
            return flow.setFailedStateAndReturnNOK(appSession);
        }

        appAuthenticator.setMaskedPin(decodedPin);
        appAuthenticator.setLastSignInAt(ZonedDateTime.now());

        if (!switchService.digidAppSwitchEnabled() ) {
            digidClient.remoteLog("824", Map.of(lowerUnderscore(ACCOUNT_ID), appAuthenticator.getAccountId()));
            throw new SwitchDisabledException();
        }

        if (flow instanceof RequestAccountAndAppFlow || flow instanceof ActivateAppWithPasswordLetterFlow) {
            Map<String, String> result = digidClient.finishRegistration(appSession.getRegistrationId(), appSession.getAccountId(), flow.getName());
            if (result.get(lowerUnderscore(STATUS)).equals("PENDING")
                && result.get(lowerUnderscore(ACTIVATION_CODE)) != null
                && result.get(lowerUnderscore(GELDIGHEIDSTERMIJN)) != null) {

                appAuthenticator.setStatus("pending");
                appAuthenticator.setActivationCode(result.get(lowerUnderscore(ACTIVATION_CODE)));
                appAuthenticator.setGeldigheidstermijn(result.get(lowerUnderscore(GELDIGHEIDSTERMIJN)));
                appAuthenticator.setRequestedAt(ZonedDateTime.now());

                return new StatusResponse("PENDING");
            } else {
                return new NokResponse();
            }
        } else {
            return ((ActivationFlow) flow).activateApp(appAuthenticator, appSession);
        }
    }
@Test
    void processNOKRequestAccountAndAppFlow(){
        Map<String, String> finishRegistrationResponse = Map.of(lowerUnderscore(STATUS), "ERROR");

        when(switchService.digidAppSwitchEnabled()).thenReturn(true);
        when(digidClientMock.finishRegistration(TEST_REGISTRATION_ID, TEST_ACCOUNT_ID, RequestAccountAndAppFlow.NAME)).thenReturn(finishRegistrationResponse);
        AppResponse appResponse = pincodeSet.process(mockedRequestFlow, mockedActivateAppRequest);

        assertTrue(appResponse instanceof NokResponse);
        assertEquals("initial", mockedAppAuthenticator.getStatus());
    }