package com.zhaohaoting.framework.utils;

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

import com.zhaohaoting.framework.ZhtLibrary;

/**
 * Created by hzxuwen on 2015/4/13.
 */
public class Preferences {
    private final static String KEY_DOWNTIME_TOGGLE = "down_time_toggle";
    private final static String KEY_SB_NOTIFY_TOGGLE = "sb_notify_toggle";
    private final static String KEY_TEAM_ANNOUNCE_CLOSED = "team_announce_closed";
    private final static String KEY_STATUS_BAR_NOTIFICATION_CONFIG = "KEY_STATUS_BAR_NOTIFICATION_CONFIG";

    // 测试过滤通知
    private final static String KEY_MSG_IGNORE = "KEY_MSG_IGNORE";
    // 响铃配置
    private final static String KEY_RING_TOGGLE = "KEY_RING_TOGGLE";
    //铃声
    private final static String KEY_RING_TONE = "KEY_RING_TONE";
    //振动
    private final static String KEY_VIBRATOR = "KEY_VIBRATOR";
    // 呼吸灯配置
    private final static String KEY_LED_TOGGLE = "KEY_LED_TOGGLE";
    // 通知栏标题配置
    private final static String KEY_NOTICE_CONTENT_TOGGLE = "KEY_NOTICE_CONTENT_TOGGLE";

    // 通知栏样式（展开、折叠）配置
    private final static String KEY_NOTIFICATION_FOLDED_TOGGLE = "KEY_NOTIFICATION_FOLDED";

    // 保存在线状态订阅时间
    private final static String KEY_SUBSCRIBE_TIME = "KEY_SUBSCRIBE_TIME";
    // 是否设置了支付密码
    private final static String KEY_IS_SET_LAY = "KEY_IS_SET_LAY";
    // 导航栏
    private final static String KEY_NAV_DATA = "KEY_NAV_DATA";
    // 群公告
    private final static String KEY_GROUP_NOTICE = "KEY_GROUP_NOTICE";


    public static final String VERSION_KEY = "version_code";//版本记录

    //用户名
    private final static String KEY_USER_NAME = "USER_NAME";
    //客服电话
    private final static String KEY_CUSTOMER_SERVICE = "CUSTOMER_SERVICE";

    public static void setMsgIgnore(boolean enable) {
        saveBoolean(KEY_MSG_IGNORE, enable);
    }

    public static boolean getMsgIgnore() {
        return getBoolean(KEY_MSG_IGNORE, false);
    }

    public static void setNotificationToggle(boolean on) {
        saveBoolean(KEY_SB_NOTIFY_TOGGLE, on);
    }

    public static boolean getNotificationToggle() {
        return getBoolean(KEY_SB_NOTIFY_TOGGLE, true);
    }

    public static void setRingToggle(boolean on) {
        saveBoolean(KEY_RING_TOGGLE, on);
    }

    public static boolean getRingToggle() {
        return getBoolean(KEY_RING_TOGGLE, true);
    }

    public static boolean getVibratorToggle() {
        return getBoolean(KEY_VIBRATOR, true);
    }

    public static void setVibratorToggle(boolean on) {
        saveBoolean(KEY_VIBRATOR, on);
    }

    public static boolean getRingToneToggle() {
        return getBoolean(KEY_RING_TONE, true);
    }

    public static void setRingToneToggle(boolean on) {
        saveBoolean(KEY_RING_TONE, on);
    }

    public static void setLedToggle(boolean on) {
        saveBoolean(KEY_LED_TOGGLE, on);
    }

    public static boolean getLedToggle() {
        return getBoolean(KEY_LED_TOGGLE, true);
    }

    public static int getVersionName() {
        return getInt(VERSION_KEY, 0);
    }

    public static void saveVersionName(int versionName) {
        saveInt(VERSION_KEY, versionName);
    }

    public static boolean getNoticeContentToggle() {
        return getBoolean(KEY_NOTICE_CONTENT_TOGGLE, false);
    }

    public static void setNoticeContentToggle(boolean on) {
        saveBoolean(KEY_NOTICE_CONTENT_TOGGLE, on);
    }

    public static void setDownTimeToggle(boolean on) {
        saveBoolean(KEY_DOWNTIME_TOGGLE, on);
    }

    public static boolean getDownTimeToggle() {
        return getBoolean(KEY_DOWNTIME_TOGGLE, false);
    }

    public static void setNotificationFoldedToggle(boolean folded) {
        saveBoolean(KEY_NOTIFICATION_FOLDED_TOGGLE, folded);
    }

    public static boolean getNotificationFoldedToggle() {
        return getBoolean(KEY_NOTIFICATION_FOLDED_TOGGLE, true);
    }

    public static void setTeamAnnounceClosed(String teamId, boolean closed) {
        saveBoolean(KEY_TEAM_ANNOUNCE_CLOSED + teamId, closed);
    }

    public static boolean getTeamAnnounceClosed(String teamId) {
        return getBoolean(KEY_TEAM_ANNOUNCE_CLOSED + teamId, false);
    }

    public static void setOnlineStateSubsTime(long time) {
        saveLong(KEY_SUBSCRIBE_TIME, time);
    }

    public static long getOnlineStateSubsTime() {
        return getLong(KEY_SUBSCRIBE_TIME, 0);
    }

    public static String getUserName() {
        return getString(KEY_USER_NAME, "");
    }

    public static void setUserName(String userName) {
        saveString(KEY_USER_NAME, userName);
    }

    public static String getCustomerService() {
        return getString(KEY_CUSTOMER_SERVICE, "");
    }

    public static void setCustomerService(String customerService) {
        saveString(KEY_CUSTOMER_SERVICE, customerService);
    }

    public static boolean getIsSetPayPwd() {
        return getBoolean(KEY_IS_SET_LAY, false);
    }

    public static void setIsSetPayPwd(boolean isSet) {
        saveBoolean(KEY_IS_SET_LAY, isSet);
    }

    public static String getNavJson() {
        return getString(KEY_NAV_DATA, "");
    }

    public static void setNavJson(String str) {
        saveString(KEY_NAV_DATA, str);
    }

    public static String getGroupNotice(String groupId) {
        return getString(groupId + KEY_GROUP_NOTICE, "");
    }

    public static void setGroupNotice(String groupId, String str) {
        saveString(groupId + KEY_GROUP_NOTICE, str);
    }


    public static boolean getBoolean(String key, boolean value) {
        return getSharedPreferences().getBoolean(key, value);
    }

    public static void saveBoolean(String key, boolean value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putBoolean(key, value);
        editor.apply();
    }

    public static void saveLong(String key, long value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putLong(key, value);
        editor.apply();
    }

    public static long getLong(String key, long value) {
        return getSharedPreferences().getLong(key, value);
    }

    public static String getString(String key, String value) {
        return getSharedPreferences().getString(key, value);
    }

    public static void saveString(String key, String value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putString(key, value);
        editor.apply();
    }

    protected static void saveInt(String key, int value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putInt(key, value);
        editor.apply();
    }

    protected static int getInt(String key, int value) {
        return getSharedPreferences().getInt(key, value);
    }

    public static SharedPreferences getSharedPreferences() {
        return ZhtLibrary.getContext().getSharedPreferences(ZhtLibrary.getSpName(), Context.MODE_PRIVATE);
    }

}
