package com.epson.iprint.prtlogger;

import android.content.Context;

import androidx.annotation.NonNull;

/**
 * log跟踪器
 *
 * @author liuyuqi.gov@msn.cn
 * @date 10/29/2020
 */
public class NewLoggerController {
    private static final int CURRENT_USER_SURVEY_DOCUMENT_VERSION = 60300;

    private NewLoggerController() {
    }

    public static boolean checkAnalyticsInvitationAndDeleteOldData(@NonNull Context context) {
        return !doesAnsweredCurrentInvitation(context);
    }

    public static boolean doesAnsweredCurrentInvitation(@NonNull Context context) {
        return LoggerRecord.getInstance().getInvitationVersion(context) >= CURRENT_USER_SURVEY_DOCUMENT_VERSION;
    }

    public static boolean doesAnsweredInvitation(@NonNull Context context) {
        return LoggerRecord.getInstance().getInvitationVersion(context) > 0;
    }

    public static void setAnswer(@NonNull Context context, boolean z) {
        LoggerRecord instance = LoggerRecord.getInstance();
        instance.setAnswer(context, z);
        instance.setInvitationVersion(context, CURRENT_USER_SURVEY_DOCUMENT_VERSION);
//        GoogleAnalytics.getInstance(context).setAppOptOut(!z);
    }

    public static boolean isLoggerEnabled(@NonNull Context context) {
        if (!doesAnsweredCurrentInvitation(context)) {
            return false;
        }
        return LoggerRecord.getInstance().getAnswer(context);
    }

    /**
     * 如果不同意则不记录log
     *
     * @param context 上下文
     */
    public static void stopLoggerIfNotAgreed(@NonNull Context context) {
        if (!isLoggerEnabled(context)) {
//            GoogleAnalytics.getInstance(context).setAppOptOut(true);
        }
    }
}