package be.iminds.ilabt.jfed;

import be.iminds.ilabt.jfed.fedmon.webapi.service.json.Server;
import be.iminds.ilabt.jfed.lowlevel.GeniUser;
import be.iminds.ilabt.jfed.lowlevel.GeniUserProvider;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.name.Names;

import javax.annotation.Nonnull;
import javax.inject.Singleton;

/**
 * BaseCliModule
 */
public class DirectUserModule extends AbstractModule {
    @Nonnull
    private final GeniUser geniUser;

    public DirectUserModule(@Nonnull GeniUser geniUser) {
        this.geniUser = geniUser;
    }

    @Override
    protected void configure() {
        bind(GeniUser.class).toInstance(geniUser);
        bind(Server.class).annotatedWith(Names.named("userServer")).toInstance(geniUser.getUserAuthorityServer());
    }

    @Provides
    @Singleton
    public GeniUserProvider provideGeniUserProvider() {
        return new GeniUserProvider() {
            @Override
            public GeniUser getLoggedInGeniUser() {
                return geniUser;
            }

            @Override
            public boolean isUserLoggedIn() {
                return true;
            }
        };
    }
}
