package com.atlassian.stash.internal.config;

import com.atlassian.applinks.api.EntityLinkService;
import com.atlassian.applinks.spi.auth.AuthenticationConfigurationManager;
import com.atlassian.applinks.spi.link.MutatingApplicationLinkService;
import com.atlassian.applinks.spi.manifest.ManifestRetriever;
import com.atlassian.applinks.spi.util.TypeAccessor;
import com.atlassian.markup.MarkupFactory;
import com.atlassian.sal.api.web.context.HttpContext;
import com.atlassian.stash.internal.plugin.OsgiServiceProxyFactory;
import com.atlassian.soy.renderer.SoyTemplateRenderer;
import com.atlassian.bitbucket.plugin.OptionalPluginInformationProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OsgiComponentsConfig {

    @Autowired
    private OsgiServiceProxyFactory osgiServiceProxyFactory;

    @Bean
    public SoyTemplateRenderer soyTemplateRenderer() {
        return osgiServiceProxyFactory.createProxy(SoyTemplateRenderer.class, 1000);
    }

    @Bean
    public MarkupFactory markupFactory() {
        return osgiServiceProxyFactory.createProxy(MarkupFactory.class, 1000);
    }

    // UAL components

    @Bean
    public MutatingApplicationLinkService applicationLinkService() {
        return osgiServiceProxyFactory.createProxy(MutatingApplicationLinkService.class);
    }

    @Bean
    public EntityLinkService entityLinkService() {
        return osgiServiceProxyFactory.createProxy(EntityLinkService.class);
    }

    @Bean
    public AuthenticationConfigurationManager authenticationConfigurationManager() {
        return osgiServiceProxyFactory.createProxy(AuthenticationConfigurationManager.class);
    }

    @Bean
    public ManifestRetriever manifestRetriever() {
        return osgiServiceProxyFactory.createProxy(ManifestRetriever.class);
    }

    @Bean
    public TypeAccessor typeAccessor() {
        return osgiServiceProxyFactory.createProxy(TypeAccessor.class);
    }

    // SAL components

    @Bean
    public HttpContext httpContext() {
        return osgiServiceProxyFactory.createProxy(HttpContext.class);
    }

    @Bean
    public OptionalPluginInformationProvider pluginInformationProvider() {
        return osgiServiceProxyFactory.createProxy(OptionalPluginInformationProvider.class, 1000);
    }

}
