package com.braintree.converters.populators.configuration;

import com.braintree.hybris.data.BraintreeGeneralConfigurationData;
import de.hybris.platform.converters.Populator;
import de.hybris.platform.core.model.BraintreeGeneralConfigurationModel;
import de.hybris.platform.servicelayer.dto.converter.ConversionException;
import de.hybris.platform.servicelayer.i18n.CommonI18NService;

public class BraintreeGeneralConfigurationPopulator implements Populator<BraintreeGeneralConfigurationModel, BraintreeGeneralConfigurationData> {

    private CommonI18NService commonI18NService;

    @Override
    public void populate(BraintreeGeneralConfigurationModel source, BraintreeGeneralConfigurationData target) throws ConversionException {
        target.setAdvancedFraudTools(source.isAdvancedFraudTools());
        target.setDropIn(source.isDropIn());
        target.setLevel2Level3(source.isLevel2Level3());
        target.setMerchantAccountId(source.getMerchantAccountId().get(commonI18NService.getCurrentCurrency().getIsocode()));
        target.setSubmitForSettlement(source.isSubmitForSettlement());
        target.setStoreInVault(source.isStoreInVault());
        target.setRestrictionOfPaymentMethodRemoval(source.isRestrictionOfPaymentMethodRemoval());
        target.setRestrictionOfPaymentMethodRemovalExpiration(source.getRestrictionOfPaymentMethodRemovalExpiration());
        target.setThreeDSecureFlow(source.getBraintreeThreeDSecureFlow().getCode());
        target.setThreeDSecureChallengeRequested(source.isBraintreeThreeDSecureChallengeRequested());
        target.setThreeDSecureSCAExemption(source.getBraintreeThreeDSecureSCAExemption().getCode());

        if (source.getDescriptorBusinessName() != null) {
            target.setDescriptorBusinessName(source.getDescriptorBusinessName());
        }
        if (source.getDescriptorProductName() != null) {
            target.setDescriptorProductName(source.getDescriptorProductName());
        }
        if (source.getDescriptorPhoneNumber() != null) {
            target.setDescriptorPhoneNumber(source.getDescriptorPhoneNumber());
        }
        if (source.getDescriptorUrl() != null) {
            target.setDescriptorUrl(source.getDescriptorUrl());
        }
    }

    public void setCommonI18NService(CommonI18NService commonI18NService) {
        this.commonI18NService = commonI18NService;
    }

}
