class AuthorizeHelper {

    public static void handleFailedAuthorizeResponse(StateManager stateManager, Evse evse) {
        if (evse.hasOngoingTransaction()) {
            StationMessageSender stationMessageSender = stateManager.getStationMessageSender();
            StationStore stationStore = stateManager.getStationStore();
            OptionList<TxStartStopPointVariableValues> stopPoints = stationStore.getTxStopPointValues();
            Optional<Connector> connector = evse.tryFindPluggedConnector();

            evse.clearToken();
            evse.stopCharging();

            if (!stopPoints.contains(TxStartStopPointVariableValues.AUTHORIZED)) {
                stationMessageSender.sendTransactionEventUpdate(evse.getId(),
                        connector.map(Connector::getId).orElse(null),
                        TransactionEventRequest.TriggerReason.DEAUTHORIZED,
                        TransactionData.ChargingState.SUSPENDED_EVSE,
                        evse.getTotalConsumedWattHours());
            } else {
                stationMessageSender.sendTransactionEventEnded(evse.getId(),
                        connector.map(Connector::getId).orElse(null),
                        TransactionEventRequest.TriggerReason.DEAUTHORIZED,
                        TransactionData.StoppedReason.DE_AUTHORIZED,
                        evse.getWattConsumedLastSession());
            }
        }
    }

    private  AuthorizeHelper();

}