package com.braintree.facade.impl;

import com.braintree.configuration.service.BrainTreeConfigService;
import com.braintree.facade.BraintreeConfigurationFacade;
import com.braintree.hybris.data.BraintreeACHConfigurationData;
import com.braintree.hybris.data.BraintreeApplePayConfigurationData;
import com.braintree.hybris.data.BraintreeConnectWithPayPalConfigurationData;
import com.braintree.hybris.data.BraintreeGeneralConfigurationData;
import com.braintree.hybris.data.BraintreeGooglePayConfigurationData;
import com.braintree.hybris.data.BraintreeHostedFieldsConfigurationData;
import com.braintree.hybris.data.BraintreeLocalPaymentsConfigurationData;
import com.braintree.hybris.data.BraintreePayPalConfigurationData;
import com.braintree.hybris.data.BraintreePluginConfigurationData;
import com.braintree.hybris.data.BraintreeSRCConfigurationData;
import com.braintree.hybris.data.BraintreeVenmoConfigurationData;
import com.braintree.util.GenericBuilder;
import de.hybris.platform.core.model.BraintreeACHConfigurationModel;
import de.hybris.platform.core.model.BraintreeApplePayConfigurationModel;
import de.hybris.platform.core.model.BraintreeConnectWithPayPalConfigurationModel;
import de.hybris.platform.core.model.BraintreeGeneralConfigurationModel;
import de.hybris.platform.core.model.BraintreeGooglePayConfigurationModel;
import de.hybris.platform.core.model.BraintreeHostedFieldsConfigurationModel;
import de.hybris.platform.core.model.BraintreeLocalPaymentsConfigurationModel;
import de.hybris.platform.core.model.BraintreePayPalConfigurationModel;
import de.hybris.platform.core.model.BraintreeSRCConfigurationModel;
import de.hybris.platform.core.model.BraintreeVenmoConfigurationModel;
import de.hybris.platform.servicelayer.dto.converter.Converter;

public class DefaultBraintreeConfigurationFacade implements BraintreeConfigurationFacade {

    private BrainTreeConfigService brainTreeConfigService;

    private Converter<BraintreeApplePayConfigurationModel, BraintreeApplePayConfigurationData> applePayConfigurationConverter;
    private Converter<BraintreeConnectWithPayPalConfigurationModel, BraintreeConnectWithPayPalConfigurationData> connectWithPayPalConfigurationConverter;
    private Converter<BraintreeGeneralConfigurationModel, BraintreeGeneralConfigurationData> generalConfigurationConverter;
    private Converter<BraintreeGooglePayConfigurationModel, BraintreeGooglePayConfigurationData> googlePayConfigurationConverter;
    private Converter<BraintreeHostedFieldsConfigurationModel, BraintreeHostedFieldsConfigurationData> hostedFieldsConfigurationConverter;
    private Converter<BraintreeLocalPaymentsConfigurationModel, BraintreeLocalPaymentsConfigurationData> localPaymentsConfigurationConverter;
    private Converter<BraintreePayPalConfigurationModel, BraintreePayPalConfigurationData> payPalConfigurationConverter;
    private Converter<BraintreeSRCConfigurationModel, BraintreeSRCConfigurationData> srcConfigurationConverter;
    private Converter<BraintreeACHConfigurationModel, BraintreeACHConfigurationData> achConfigurationConverter;
    private Converter<BraintreeVenmoConfigurationModel, BraintreeVenmoConfigurationData> venmoConfigurationConverter;

    @Override
    public BraintreeGeneralConfigurationData getBraintreeGeneralConfigurationData() {
        return generalConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeGeneralConfiguration());
    }

    @Override
    public BraintreeHostedFieldsConfigurationData getBraintreeHostedFieldsConfigurationData() {
        return hostedFieldsConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeHostedFieldsConfiguration());
    }

    @Override
    public BraintreePayPalConfigurationData getBraintreePayPalConfigurationData() {
        BraintreePayPalConfigurationData configurationData = payPalConfigurationConverter
                .convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreePayPalConfiguration());
        return configurationData;
    }

    @Override
    public BraintreeApplePayConfigurationData getBraintreeApplePayConfigurationData() {
        return applePayConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeApplePayConfiguration());
    }

    @Override
    public BraintreeGooglePayConfigurationData getBraintreeGooglePayConfigurationData() {
        BraintreeGooglePayConfigurationData configurationData = googlePayConfigurationConverter
                .convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeGooglePayConfiguration());
        return configurationData;
    }

    @Override
    public BraintreeLocalPaymentsConfigurationData getBraintreeLocalPaymentsConfigurationData() {
        BraintreeLocalPaymentsConfigurationData configurationData = localPaymentsConfigurationConverter
                .convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeLocalPaymentsConfiguration());
        return configurationData;
    }

    @Override
    public BraintreeVenmoConfigurationData getBraintreeVenmoConfigurationData() {
        return venmoConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeVenmoConfiguration());
    }

    @Override
    public BraintreeSRCConfigurationData getBraintreeSRCConfigurationData() {
        return srcConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeSRCConfiguration());
    }

    @Override
    public BraintreeConnectWithPayPalConfigurationData getBraintreeConnectWithPayPalConfigurationData() {
        return connectWithPayPalConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeConnectWithPayPalConfiguration());
    }

    @Override
    public BraintreeACHConfigurationData getBraintreeACHConfigurationData() {
        return achConfigurationConverter.convert(brainTreeConfigService.getBrainTreePluginConfiguration().getBraintreeACHConfiguration());
    }

    @Override
    public BraintreePluginConfigurationData getBraintreePluginConfigurationData() {
        return GenericBuilder.of(BraintreePluginConfigurationData::new)
                .with(BraintreePluginConfigurationData::setConnectWithPayPalConfigurationData, getBraintreeConnectWithPayPalConfigurationData())
                .with(BraintreePluginConfigurationData::setSrcConfigurationData, getBraintreeSRCConfigurationData())
                .with(BraintreePluginConfigurationData::setVenmoConfigurationData, getBraintreeVenmoConfigurationData())
                .with(BraintreePluginConfigurationData::setLocalPaymentsConfigurationData, getBraintreeLocalPaymentsConfigurationData())
                .with(BraintreePluginConfigurationData::setApplePayConfigurationData, getBraintreeApplePayConfigurationData())
                .with(BraintreePluginConfigurationData::setGooglePayConfigurationData, getBraintreeGooglePayConfigurationData())
                .with(BraintreePluginConfigurationData::setPayPalConfigurationData, getBraintreePayPalConfigurationData())
                .with(BraintreePluginConfigurationData::setHostedFieldsConfigurationData, getBraintreeHostedFieldsConfigurationData())
                .with(BraintreePluginConfigurationData::setGeneralConfigurationData, getBraintreeGeneralConfigurationData())
                .with(BraintreePluginConfigurationData::setAchConfigurationData, getBraintreeACHConfigurationData())
                .build();
    }

    public void setBrainTreeConfigService(BrainTreeConfigService brainTreeConfigService) {
        this.brainTreeConfigService = brainTreeConfigService;
    }

    public void setApplePayConfigurationConverter(Converter<BraintreeApplePayConfigurationModel, BraintreeApplePayConfigurationData> applePayConfigurationConverter) {
        this.applePayConfigurationConverter = applePayConfigurationConverter;
    }

    public void setConnectWithPayPalConfigurationConverter(Converter<BraintreeConnectWithPayPalConfigurationModel, BraintreeConnectWithPayPalConfigurationData> connectWithPayPalConfigurationConverter) {
        this.connectWithPayPalConfigurationConverter = connectWithPayPalConfigurationConverter;
    }

    public void setGeneralConfigurationConverter(Converter<BraintreeGeneralConfigurationModel, BraintreeGeneralConfigurationData> generalConfigurationConverter) {
        this.generalConfigurationConverter = generalConfigurationConverter;
    }

    public void setGooglePayConfigurationConverter(Converter<BraintreeGooglePayConfigurationModel, BraintreeGooglePayConfigurationData> googlePayConfigurationConverter) {
        this.googlePayConfigurationConverter = googlePayConfigurationConverter;
    }

    public void setHostedFieldsConfigurationConverter(Converter<BraintreeHostedFieldsConfigurationModel, BraintreeHostedFieldsConfigurationData> hostedFieldsConfigurationConverter) {
        this.hostedFieldsConfigurationConverter = hostedFieldsConfigurationConverter;
    }

    public void setLocalPaymentsConfigurationConverter(Converter<BraintreeLocalPaymentsConfigurationModel, BraintreeLocalPaymentsConfigurationData> localPaymentsConfigurationConverter) {
        this.localPaymentsConfigurationConverter = localPaymentsConfigurationConverter;
    }

    public void setPayPalConfigurationConverter(Converter<BraintreePayPalConfigurationModel, BraintreePayPalConfigurationData> payPalConfigurationConverter) {
        this.payPalConfigurationConverter = payPalConfigurationConverter;
    }

    public void setSrcConfigurationConverter(Converter<BraintreeSRCConfigurationModel, BraintreeSRCConfigurationData> srcConfigurationConverter) {
        this.srcConfigurationConverter = srcConfigurationConverter;
    }

    public void setVenmoConfigurationConverter(Converter<BraintreeVenmoConfigurationModel, BraintreeVenmoConfigurationData> venmoConfigurationConverter) {
        this.venmoConfigurationConverter = venmoConfigurationConverter;
    }

    public void setAchConfigurationConverter(Converter<BraintreeACHConfigurationModel, BraintreeACHConfigurationData> achConfigurationConverter) {
        this.achConfigurationConverter = achConfigurationConverter;
    }
}
