package org.rakam.ui;

import com.google.inject.Binder;
import com.google.inject.Scopes;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.multibindings.OptionalBinder;
import org.rakam.plugin.RakamModule;
import org.rakam.server.http.HttpService;
import org.rakam.server.http.RakamHttpRequest;
import org.rakam.ui.customreport.CustomReportMetadata;
import org.rakam.ui.page.CustomPageDatabase;

import javax.ws.rs.GET;
import javax.ws.rs.Path;

public class RakamWebUIFallbackModule extends RakamModule {
    @Override
    protected void setup(Binder binder) {
        OptionalBinder.newOptionalBinder(binder, CustomPageDatabase.class);
        OptionalBinder.newOptionalBinder(binder, CustomReportMetadata.class);
        OptionalBinder.newOptionalBinder(binder, ReportMetadata.class);
        OptionalBinder.newOptionalBinder(binder, DashboardService.class);

        if(!"true".equals(getConfig("ui.enable"))) {
            Multibinder.newSetBinder(binder, HttpService.class).addBinding()
                    .to(RootAPIInformationService.class).in(Scopes.SINGLETON);
        }
    }

    @Override
    public String name() {
        return "Fallback for Rakam API BI Module";
    }

    @Override
    public String description() {
        return null;
    }

    @Path("/")
    public static class RootAPIInformationService extends HttpService {
        @GET
        @Path("/")
        public void main(RakamHttpRequest request) {
            request.response("Rakam API is successfully installed! \n---------- \n" +
                    "Visit app.rakam.io to register the API with Rakam BI or api.rakam.io for API documentation.")
                    .end();
        }
    }
}

@@ -16,16 +16,60 @@
 am.ui;%0A%0A
+import com.google.auto.service.AutoService;%0A
 import c
@@ -510,16 +510,48 @@
 .Path;%0A%0A
+@AutoService(RakamModule.class)%0A
 public c

add @RakamModule annotation to UI fallback module