package be.iminds.ilabt.jfed.experimenter_gui.config;

import be.iminds.ilabt.jfed.experimenter_gui.JFedVersionInfo;
import be.iminds.ilabt.jfed.fedmon.webapi.service.json.UserInfo;
import be.iminds.ilabt.jfed.fedmon.webapi.service.json.UserInfoBuilder;
import be.iminds.ilabt.jfed.preferences.CorePreferenceKey;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import be.iminds.ilabt.jfed.util.GeniUrn;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * User: twalcari
 * Date: 4/25/2016
 * Time: 14:52
 */
@Singleton
public class UserInfoProvider {
    private final JFedVersionInfo jFedVersionInfo;
    private final List<String> extraFlags;

    @Inject
    public UserInfoProvider(JFedVersionInfo jFedVersionInfo, JFedPreferences jFedPreferences) {
        this.jFedVersionInfo = jFedVersionInfo;

        extraFlags = jFedPreferences.getStringList(CorePreferenceKey.PREF_GUICONFIG_EXTRA_FLAGS);
    }


    public UserInfo createUserInfo(GeniUrn userUrn){

        UserInfoBuilder userInfoBuilder = new UserInfoBuilder();
        userInfoBuilder.setUrn(userUrn);

        userInfoBuilder.setVersionJava(System.getProperty("java.version"));
        userInfoBuilder.setVersionJavaVendor(System.getProperty("java.vendor"));
        userInfoBuilder.setVersionJavaSpec(System.getProperty("java.specification.version"));

        userInfoBuilder.setVersionOs(System.getProperty("os.name") + " " + System.getProperty("os.version"));
        userInfoBuilder.setVersionArch(System.getProperty("os.arch"));

        userInfoBuilder.setVersionJFed(jFedVersionInfo.getFullVersionString());

        userInfoBuilder.setExtra(extraFlags);
        return userInfoBuilder.create();
    }


}
