package be.iminds.ilabt.jfed.highlevel;

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 be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.util.GeniUrn;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import org.mockito.Mockito;

import javax.inject.Singleton;

/**
 * User: twalcari
 * Date: 11/27/2014
 * Time: 16:32
 */

public class MockGeniUserModule  extends AbstractModule{

    public static final String LOGGED_IN_USER_URN_STRING = "urn:publicid:IDN+wall2.ilabt.iminds.be+user+wvdemeer";

    public static final GeniUrn LOGGED_IN_USER_URN = GeniUrn.parse(LOGGED_IN_USER_URN_STRING);


    @Provides
    @Singleton
    public GeniUser provideGeniUser(TestbedInfoSource testbedInfoSource) {
        Server userAuthority = testbedInfoSource.getByUrnExact(
                "urn:publicid:IDN+wall2.ilabt.iminds.be+authority+cm");

        GeniUser loggedInUser = Mockito.mock(GeniUser.class);
        Mockito.when(loggedInUser.getUserUrn()).thenReturn(LOGGED_IN_USER_URN);
        Mockito.when(loggedInUser.getUserUrnString()).thenReturn(LOGGED_IN_USER_URN_STRING);
        Mockito.when(loggedInUser.getUserAuthorityServer()).thenReturn(userAuthority);

        return loggedInUser;
    }


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

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

    @Override
    protected void configure() {

    }
}
