package com.github.material.monitor.demo.helper;

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

/**
 * 持久化用户隐私协议同意状态（对接文档 §3：须在用户同意后再 init）。
 */
public final class PrivacyConsentStore {

    private static final String PREFS_NAME = "material_monitor_demo_cn_prefs";
    private static final String KEY_PRIVACY_AGREED = "privacy_agreed";

    private PrivacyConsentStore() {
    }

    public static boolean isAgreed(Context context) {
        return prefs(context).getBoolean(KEY_PRIVACY_AGREED, false);
    }

    public static void setAgreed(Context context) {
        prefs(context).edit().putBoolean(KEY_PRIVACY_AGREED, true).apply();
    }

    private static SharedPreferences prefs(Context context) {
        return context.getApplicationContext()
                .getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
    }
}
