package com.braintreeocc.validators.impl;

import com.braintree.hybris.data.ws.PayPalPaymentRequestWsDTO;
import com.braintreeocc.validators.BrainTreeValidator;
import com.braintreeocc.constants.BraintreeoccWebConstants;
import org.springframework.util.Assert;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

public class BraintreePayPalPaymentRequestValidator implements BrainTreeValidator {

    @Override
    public boolean supports(final Class clazz) {
        return PayPalPaymentRequestWsDTO.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(final Object target, final Errors errors) {

        final PayPalPaymentRequestWsDTO paymentResponse = (PayPalPaymentRequestWsDTO) target;

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "nonce", BraintreeoccWebConstants.FIELD_REQUIRED_MESSAGE_ID);

        Assert.notNull(paymentResponse.getDetails(), "Details object must not be null");
    }

}
