package com.epson.iprint.prtlogger;

import android.content.Context;
import android.content.SharedPreferences;



public class LoggerRecord {
    private static final String ANALYTICS_PREFS_NAME = "logger6_3";
    private static final String PREFS_KEY_LOGGER_ANSWER = "answer";
    private static final String PREFS_KEY_LOGGER_VERSION = "logger_version";
    private static LoggerRecord sLoggerRecord;

    public static synchronized LoggerRecord getInstance() {
        LoggerRecord loggerRecord;
        synchronized (LoggerRecord.class) {
            if (sLoggerRecord == null) {
                sLoggerRecord = new LoggerRecord();
            }
            loggerRecord = sLoggerRecord;
        }
        return loggerRecord;
    }

    @VisibleForTesting
    static void replaceInstance(LoggerRecord loggerRecord) {
        sLoggerRecord = loggerRecord;
    }

    public int getInvitationVersion(@NonNull Context context) {
        return getPreferences(context).getInt(PREFS_KEY_LOGGER_VERSION, 0);
    }

    public void setInvitationVersion(@NonNull Context context, int i) {
        getPreferences(context).edit().putInt(PREFS_KEY_LOGGER_VERSION, i).apply();
    }

    public void setAnswer(@NonNull Context context, boolean z) {
        getPreferences(context).edit().putBoolean(PREFS_KEY_LOGGER_ANSWER, z).apply();
    }

    public boolean getAnswer(@NonNull Context context) {
        return getPreferences(context).getBoolean(PREFS_KEY_LOGGER_ANSWER, false);
    }

    private SharedPreferences getPreferences(@NonNull Context context) {
        return context.getSharedPreferences(ANALYTICS_PREFS_NAME, 0);
    }
}
