package io.trustbuilder.mfa.android.demoapp.config;

import android.annotation.SuppressLint;
import android.os.Build;
import android.provider.Settings;

import java.io.Serializable;

import io.trustbuilder.mfa.android.demoapp.BuildConfig;
import io.trustbuilder.mfa.lib.definition.ApplicationInfo;
import io.trustbuilder.mfa.lib.definition.IHost;
import io.trustbuilder.mfa.lib.definition.OsInfo;
import io.trustbuilder.mfa.lib.definition.SecureTokenTypeEnum;

public class ConfigHost implements IHost, Serializable {
    private final ApplicationInfo appInfo;
    private final OsInfo osInfo;
    private final String serial;
    private final String name;
    private final SecureTokenTypeEnum type;
    private final String appAlias;

    private static ConfigHost instance;

    public static ConfigHost getInstance() {
        if (instance == null) {
            instance = new ConfigHost();
        }
        return instance;
    }

    @SuppressLint("HardwareIds")
    private ConfigHost() {
        appInfo = ApplicationInfo.builder()
                .id(BuildConfig.APPLICATION_ID)
                .type(BuildConfig.BUILD_TYPE)
                .name(BuildConfig.APPLICATION_NAME)
                .version(BuildConfig.VERSION_NAME)
                .build();
        osInfo = OsInfo.builder()
                .name("Android")
                .version(String.valueOf(Build.VERSION.RELEASE))
                .build();
        serial = Settings.Secure.ANDROID_ID;
        name = BuildConfig.APPLICATION_NAME;
        type = SecureTokenTypeEnum.MOBILE;
        appAlias = BuildConfig.APP_ALIAS;
    }

    @Override
    public ApplicationInfo getAppInfo() {
        return appInfo;
    }

    @Override
    public OsInfo getOsInfo() {
        return osInfo;
    }

    @Override
    public String getSerial() {
        return serial;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public SecureTokenTypeEnum getTknType() {
        return type;
    }

    @Override
    public String getAppAlias() {
        return appAlias;
    }
}
