package com.braintree.converters.populators.configuration;

import com.braintree.enums.BraintreePaymentMethodLimitData;
import com.braintree.hybris.data.BraintreePayPalConfigurationData;
import de.hybris.platform.converters.Populator;
import de.hybris.platform.core.model.BraintreePayPalConfigurationModel;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;

public class BraintreePayPalConfigurationPopulator implements Populator<BraintreePayPalConfigurationModel, BraintreePayPalConfigurationData> {

    @Override
    public void populate(BraintreePayPalConfigurationModel source, BraintreePayPalConfigurationData target) throws ConversionException {
        target.setExpressCheckout(source.isPayPalEnabled() && source.isExpressCheckout());
        target.setPayLater(source.isPayLater());
        target.setIntent(source.getIntent().getCode().toLowerCase());
        target.setBillingAgreementText(source.getBillingAgreementText());
        target.setChangePaymentMethodButton(source.isChangePaymentMethodButton());
        target.setPayLaterForNonUsCountries(source.isPayLaterForNonUsCountries());
        target.setPayPalEnabled(source.isPayPalEnabled());
        target.setCreditMessagesEnabled(source.isCreditMessagesEnabled());
        target.setSavedPayPalAccountLimit(BraintreePaymentMethodLimitData.valueOf(source.getSavedPayPalAccountLimit().getCode()));
    }
}
