package com.braintree.facade.impl;

import com.braintree.configuration.service.BrainTreeConfigService;
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 de.hybris.bootstrap.annotations.UnitTest;
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.BraintreePluginConfigurationModel;
import de.hybris.platform.core.model.BraintreeSRCConfigurationModel;
import de.hybris.platform.core.model.BraintreeVenmoConfigurationModel;
import de.hybris.platform.servicelayer.dto.converter.Converter;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.when;

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class DefaultBraintreeConfigurationFacadeTest {

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

    @InjectMocks
    private DefaultBraintreeConfigurationFacade unit;

    @Mock
    private BraintreePluginConfigurationModel pluginConfigurationModel;
    @Mock
    private BraintreeGeneralConfigurationModel generalConfigurationModel;
    @Mock
    private BraintreeHostedFieldsConfigurationModel hostedFieldsConfigurationModel;
    @Mock
    private BraintreePayPalConfigurationModel payPalConfigurationModel;
    @Mock
    private BraintreeApplePayConfigurationModel applePayConfigurationModel;
    @Mock
    private BraintreeGooglePayConfigurationModel googlePayConfigurationModel;
    @Mock
    private BraintreeLocalPaymentsConfigurationModel localPaymentsConfigurationModel;
    @Mock
    private BraintreeVenmoConfigurationModel venmoConfigurationModel;
    @Mock
    private BraintreeSRCConfigurationModel srcConfigurationModel;
    @Mock
    private BraintreeConnectWithPayPalConfigurationModel connectWithPayPalConfigurationModel;
    @Mock
    private BraintreeACHConfigurationModel achConfigurationModel;


    @Test
    public void shouldReturnBraintreeGeneralConfigurationData() {
        BraintreeGeneralConfigurationData data = new BraintreeGeneralConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(generalConfigurationConverter.convert(generalConfigurationModel)).thenReturn(data);
        when(pluginConfigurationModel.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);

        BraintreeGeneralConfigurationData result = unit.getBraintreeGeneralConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeHostedFieldsConfigurationData() {
        BraintreeHostedFieldsConfigurationData data = new BraintreeHostedFieldsConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeHostedFieldsConfiguration()).thenReturn(hostedFieldsConfigurationModel);
        when(hostedFieldsConfigurationConverter.convert(hostedFieldsConfigurationModel)).thenReturn(data);

        BraintreeHostedFieldsConfigurationData result = unit.getBraintreeHostedFieldsConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreePayPalConfigurationData() {
        BraintreePayPalConfigurationData data = new BraintreePayPalConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreePayPalConfiguration()).thenReturn(payPalConfigurationModel);
        when(payPalConfigurationConverter.convert(payPalConfigurationModel)).thenReturn(data);

        BraintreePayPalConfigurationData result = unit.getBraintreePayPalConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeApplePayConfigurationData() {
        BraintreeApplePayConfigurationData data = new BraintreeApplePayConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeApplePayConfiguration()).thenReturn(applePayConfigurationModel);
        when(applePayConfigurationConverter.convert(applePayConfigurationModel)).thenReturn(data);

        BraintreeApplePayConfigurationData result = unit.getBraintreeApplePayConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeGooglePayConfigurationData() {
        BraintreeGooglePayConfigurationData data = new BraintreeGooglePayConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeGooglePayConfiguration()).thenReturn(googlePayConfigurationModel);
        when(googlePayConfigurationConverter.convert(googlePayConfigurationModel)).thenReturn(data);

        BraintreeGooglePayConfigurationData result = unit.getBraintreeGooglePayConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeLocalPaymentConfigurationData() {
        BraintreeLocalPaymentsConfigurationData data = new BraintreeLocalPaymentsConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeLocalPaymentsConfiguration()).thenReturn(localPaymentsConfigurationModel);
        when(localPaymentsConfigurationConverter.convert(localPaymentsConfigurationModel)).thenReturn(data);

        BraintreeLocalPaymentsConfigurationData result = unit.getBraintreeLocalPaymentsConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeVenmoConfigurationData() {
        BraintreeVenmoConfigurationData data = new BraintreeVenmoConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeVenmoConfiguration()).thenReturn(venmoConfigurationModel);
        when(venmoConfigurationConverter.convert(venmoConfigurationModel)).thenReturn(data);

        BraintreeVenmoConfigurationData result = unit.getBraintreeVenmoConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeSRCConfigurationData() {
        BraintreeSRCConfigurationData data = new BraintreeSRCConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeSRCConfiguration()).thenReturn(srcConfigurationModel);
        when(srcConfigurationConverter.convert(srcConfigurationModel)).thenReturn(data);

        BraintreeSRCConfigurationData result = unit.getBraintreeSRCConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeConnectWithPayPalConfigurationData() {
        BraintreeConnectWithPayPalConfigurationData data = new BraintreeConnectWithPayPalConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeConnectWithPayPalConfiguration()).thenReturn(connectWithPayPalConfigurationModel);
        when(connectWithPayPalConfigurationConverter.convert(connectWithPayPalConfigurationModel)).thenReturn(data);

        BraintreeConnectWithPayPalConfigurationData result = unit.getBraintreeConnectWithPayPalConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreeACHConfigurationData() {
        BraintreeACHConfigurationData data = new BraintreeACHConfigurationData();
        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);
        when(pluginConfigurationModel.getBraintreeACHConfiguration()).thenReturn(achConfigurationModel);
        when(achConfigurationConverter.convert(achConfigurationModel)).thenReturn(data);

        BraintreeACHConfigurationData result = unit.getBraintreeACHConfigurationData();

        assertEquals(data, result);
    }

    @Test
    public void shouldReturnBraintreePluginConfigurationData() {
        BraintreeGeneralConfigurationData generalConfigurationData = new BraintreeGeneralConfigurationData();
        BraintreeHostedFieldsConfigurationData hostedFieldsConfigurationData = new BraintreeHostedFieldsConfigurationData();
        BraintreePayPalConfigurationData payPalConfigurationData = new BraintreePayPalConfigurationData();
        BraintreeApplePayConfigurationData applePayConfigurationData = new BraintreeApplePayConfigurationData();
        BraintreeGooglePayConfigurationData googlePayConfigurationData = new BraintreeGooglePayConfigurationData();
        BraintreeLocalPaymentsConfigurationData localPaymentsConfigurationData = new BraintreeLocalPaymentsConfigurationData();
        BraintreeVenmoConfigurationData venmoConfigurationData = new BraintreeVenmoConfigurationData();
        BraintreeSRCConfigurationData srcConfigurationData = new BraintreeSRCConfigurationData();
        BraintreeConnectWithPayPalConfigurationData connectWithPayPalConfigurationData = new BraintreeConnectWithPayPalConfigurationData();
        BraintreeACHConfigurationData achConfigurationData = new BraintreeACHConfigurationData();

        when(brainTreeConfigService.getBrainTreePluginConfiguration()).thenReturn(pluginConfigurationModel);

        when(pluginConfigurationModel.getBraintreeGeneralConfiguration()).thenReturn(generalConfigurationModel);
        when(pluginConfigurationModel.getBraintreeHostedFieldsConfiguration()).thenReturn(hostedFieldsConfigurationModel);
        when(pluginConfigurationModel.getBraintreePayPalConfiguration()).thenReturn(payPalConfigurationModel);
        when(pluginConfigurationModel.getBraintreeApplePayConfiguration()).thenReturn(applePayConfigurationModel);
        when(pluginConfigurationModel.getBraintreeGooglePayConfiguration()).thenReturn(googlePayConfigurationModel);
        when(pluginConfigurationModel.getBraintreeLocalPaymentsConfiguration()).thenReturn(localPaymentsConfigurationModel);
        when(pluginConfigurationModel.getBraintreeVenmoConfiguration()).thenReturn(venmoConfigurationModel);
        when(pluginConfigurationModel.getBraintreeSRCConfiguration()).thenReturn(srcConfigurationModel);
        when(pluginConfigurationModel.getBraintreeConnectWithPayPalConfiguration()).thenReturn(connectWithPayPalConfigurationModel);
        when(pluginConfigurationModel.getBraintreeACHConfiguration()).thenReturn(achConfigurationModel);

        when(generalConfigurationConverter.convert(generalConfigurationModel)).thenReturn(generalConfigurationData);
        when(hostedFieldsConfigurationConverter.convert(hostedFieldsConfigurationModel)).thenReturn(hostedFieldsConfigurationData);
        when(payPalConfigurationConverter.convert(payPalConfigurationModel)).thenReturn(payPalConfigurationData);
        when(applePayConfigurationConverter.convert(applePayConfigurationModel)).thenReturn(applePayConfigurationData);
        when(googlePayConfigurationConverter.convert(googlePayConfigurationModel)).thenReturn(googlePayConfigurationData);
        when(localPaymentsConfigurationConverter.convert(localPaymentsConfigurationModel)).thenReturn(localPaymentsConfigurationData);
        when(venmoConfigurationConverter.convert(venmoConfigurationModel)).thenReturn(venmoConfigurationData);
        when(srcConfigurationConverter.convert(srcConfigurationModel)).thenReturn(srcConfigurationData);
        when(connectWithPayPalConfigurationConverter.convert(connectWithPayPalConfigurationModel)).thenReturn(connectWithPayPalConfigurationData);
        when(achConfigurationConverter.convert(achConfigurationModel)).thenReturn(achConfigurationData);

        BraintreePluginConfigurationData result = unit.getBraintreePluginConfigurationData();

        assertNotNull(result);
        assertEquals(generalConfigurationData, result.getGeneralConfigurationData());
        assertEquals(hostedFieldsConfigurationData, result.getHostedFieldsConfigurationData());
        assertEquals(payPalConfigurationData, result.getPayPalConfigurationData());
        assertEquals(applePayConfigurationData, result.getApplePayConfigurationData());
        assertEquals(googlePayConfigurationData, result.getGooglePayConfigurationData());
        assertEquals(localPaymentsConfigurationData, result.getLocalPaymentsConfigurationData());
        assertEquals(venmoConfigurationData, result.getVenmoConfigurationData());
        assertEquals(srcConfigurationData, result.getSrcConfigurationData());
        assertEquals(connectWithPayPalConfigurationData, result.getConnectWithPayPalConfigurationData());
        assertEquals(achConfigurationData, result.getAchConfigurationData());
    }

}
