package com.braintree.customersupportbackoffice.handler;

import com.hybris.cockpitng.dataaccess.facades.object.exceptions.ObjectSavingException;
import com.hybris.cockpitng.service.ExceptionTranslationHandler;

public class BrainTreePayPalStylesConfigurationValidationTranslationHandler implements ExceptionTranslationHandler {

    private static final String BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR =
            "BrainTreePayPalStylesConfigurationValidationInterceptor";
    private static final String COLON_SYMBOL = ":";

    @Override
    public boolean canHandle(Throwable throwable) {
        return throwable instanceof ObjectSavingException &&
                throwable.getCause().getMessage().contains(
                        BRAIN_TREE_PAY_PAL_STYLES_CONFIGURATION_VALIDATION_INTERCEPTOR);
    }

    @Override
    public String toString(Throwable throwable) {
        return throwable.getCause().getMessage().substring(throwable.getCause().getMessage().indexOf(COLON_SYMBOL) + 1);
    }

}
