package com.braintree.services.impl;

import com.braintree.services.BrainTreeStylesConfigurationService;
import de.hybris.platform.core.model.BraintreeApplePayStylesConfigurationModel;
import de.hybris.platform.core.model.BraintreeGooglePayStylesConfigurationModel;
import de.hybris.platform.core.model.BraintreePayPalStylesConfigurationModel;
import de.hybris.platform.core.model.BraintreePluginConfigurationModel;
import de.hybris.platform.core.model.BraintreeApplePayConfigurationModel;
import de.hybris.platform.core.model.BraintreeGooglePayConfigurationModel;
import de.hybris.platform.core.model.BraintreePayPalConfigurationModel;
import de.hybris.platform.store.BaseStoreModel;
import de.hybris.platform.store.services.BaseStoreService;
import org.assertj.core.util.Lists;

import java.util.Collection;
import java.util.Optional;

public class DefaultBrainTreeStylesConfigurationService implements BrainTreeStylesConfigurationService {

    private BaseStoreService baseStoreService;

    @Override
    public Collection<BraintreeApplePayStylesConfigurationModel> getApplePayStyleConfigurations() {
        return Optional.of(baseStoreService.getCurrentBaseStore())
                .map(BaseStoreModel::getBraintreePluginConfiguration)
                .map(BraintreePluginConfigurationModel::getBraintreeApplePayConfiguration)
                .map(BraintreeApplePayConfigurationModel::getBraintreeApplePayStylesConfiguration)
                .orElse(Lists.emptyList());
    }

    @Override
    public Collection<BraintreeGooglePayStylesConfigurationModel> getGooglePayStyleConfigurations() {
        return Optional.of(baseStoreService.getCurrentBaseStore())
                .map(BaseStoreModel::getBraintreePluginConfiguration)
                .map(BraintreePluginConfigurationModel::getBraintreeGooglePayConfiguration)
                .map(BraintreeGooglePayConfigurationModel::getBraintreeGooglePayStylesConfiguration)
                .orElse(Lists.emptyList());
    }

    @Override
    public Collection<BraintreePayPalStylesConfigurationModel> getPayPalStyleConfigurations() {
        return Optional.of(baseStoreService.getCurrentBaseStore())
                .map(BaseStoreModel::getBraintreePluginConfiguration)
                .map(BraintreePluginConfigurationModel::getBraintreePayPalConfiguration)
                .map(BraintreePayPalConfigurationModel::getBraintreePayPalStylesConfiguration)
                .orElse(Lists.emptyList());
    }

    public void setBaseStoreService(BaseStoreService baseStoreService) {
        this.baseStoreService = baseStoreService;
    }
}
