package io.airlift.jaxrs;

import com.google.inject.Binder;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;

import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.multibindings.Multibinder.newSetBinder;
import static java.util.Objects.requireNonNull;

public class JaxrsBinder
{
    private final Multibinder<Object> resourceBinder;
    private final Binder binder;

    private JaxrsBinder(Binder binder)
    {
        this.binder = requireNonNull(binder, "binder is null").skipSources(getClass());
        this.resourceBinder = newSetBinder(binder, Object.class, JaxrsResource.class).permitDuplicates();
    }

    public static JaxrsBinder jaxrsBinder(Binder binder)
    {
        return new JaxrsBinder(binder);
    }

    public void bind(Class<?> implementation)
    {
        binder.bind(implementation).in(SINGLETON);
        resourceBinder.addBinding().to(implementation).in(SINGLETON);
    }

    public void bind(TypeLiteral<?> implementation)
    {
        binder.bind(implementation).in(SINGLETON);
        resourceBinder.addBinding().to(implementation).in(SINGLETON);
    }

    public void bind(Key<?> targetKey)
    {
        binder.bind(targetKey).in(SINGLETON);
        resourceBinder.addBinding().to(targetKey).in(SINGLETON);
    }

    public void bindInstance(Object instance)
    {
        resourceBinder.addBinding().toInstance(instance);
    }
}

@@ -20,16 +20,64 @@
 jaxrs;%0A%0A
+import com.google.common.collect.ImmutableList;%0A
 import c
@@ -220,16 +220,253 @@
 ibinder;
+%0Aimport org.glassfish.jersey.server.wadl.internal.WadlResource;%0Aimport org.glassfish.jersey.server.wadl.processor.OptionsMethodProcessor;%0Aimport org.glassfish.jersey.server.wadl.processor.WadlModelProcessor;%0A%0Aimport java.util.Collection;
 %0A%0Aimport
@@ -1745,11 +1745,194 @@
 );%0A    %7D
+%0A%0A    public static Collection%3CClass%3C?%3E%3E getBuiltinResources()%0A    %7B%0A        return ImmutableList.of(WadlResource.class, WadlModelProcessor.class, OptionsMethodProcessor.class);%0A    %7D
 %0A%7D%0A

Add JaxrsBinder method to get built in JaxRS resources