using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Touka;
public class TKGUtils
{
    /// 
    /// 是否首次触达某个事件
    /// 
    /// 
    /// 
    public static bool IfFirstCheckPlayerPrefs(string _key)
    {
        var isFirstClick = GetPlayerPrefsIntByKey(_key) == 0;
        SavePlayerPrefsIntByKeyValue(_key, 1);
        return isFirstClick;
    }
    /// 
    /// 本地存int
    ///
    /// key 内部拼接了前缀:Touka_
    /// 
    /// 
    /// 
    /// 
    public static int GetPlayerPrefsIntByKey(string _key, int _defaultValue = 0)
    {
        int value = PlayerPrefs.GetInt(string.Format("{0}{1}", TKGStringPlayerPrefs.TOUKA_PREFIX, _key), _defaultValue);
        return value;
    }
    /// 
    /// 本地取int
    ///
    /// key 内部拼接了前缀:Touka_
    /// 
    /// 
    /// 
    public static void SavePlayerPrefsIntByKeyValue(string _key, int _newValue)
    {
        PlayerPrefs.SetInt(string.Format("{0}{1}", TKGStringPlayerPrefs.TOUKA_PREFIX, _key), _newValue);
        PlayerPrefs.Save();
    }
    /// 
    /// 本地存string
    ///
    /// key 内部拼接了前缀:Touka_
    /// 
    /// 
    /// 
    /// 
    public static string GetPlayerPrefsStringByKey(string _key, string _defaultValue = "")
    {
        string value = PlayerPrefs.GetString(string.Format("{0}{1}", TKGStringPlayerPrefs.TOUKA_PREFIX, _key), _defaultValue);
        return value;
    }
    /// 
    /// 本地取string
    ///
    /// key 内部拼接了前缀:Touka_
    /// 
    /// 
    /// 
    public static void SavePlayerPrefsStringByKeyValue(string _key, string _newValue)
    {
        PlayerPrefs.SetString(string.Format("{0}{1}", TKGStringPlayerPrefs.TOUKA_PREFIX, _key), _newValue);
        PlayerPrefs.Save();
    }
    /// 
    /// 缓存当前时间
    /// 
    /// 
    public static void SaveCurrTime2PlayerPrefs(string _key)
    {
        DateTime date1 = DateTime.Now;
        string s1 = date1.ToString();
        SavePlayerPrefsStringByKeyValue(_key, s1);
    }
    /// 
    /// 缓存本地时间为string
    /// 
    /// 
    /// 
    public static void SaveCurrTime2PlayerPrefsWithStringDate(string _key, string _dateStr)
    {
        SavePlayerPrefsStringByKeyValue(_key, _dateStr);
    }
    /// 
    /// 取出缓存string时间为 DateTime
    /// 
    /// 
    /// 
    public static DateTime GetDateTimeFromPlayerPrefs(string _key)
    {
        string firstDateValue = GetPlayerPrefsStringByKey(_key);
        if (string.IsNullOrEmpty(firstDateValue))
        {
            return new DateTime(1990, 1, 1, 0, 0, 0);
        }
        DateTime dateOld = Convert.ToDateTime(firstDateValue);
        return dateOld;
    }
    /// 
    /// equal double
    /// 
    /// 
    /// 
    /// 
    public static bool equalDouble(double a, double b)
    {
        if ((a - b > -0.000001) && (a - b) < 0.000001)
            return true;
        else
            return false;
    }
    /// 
    /// Floats the equal.
    /// 
    /// true, if equal was floated, false otherwise.
    /// The alpha component.
    /// The blue component.
    public static bool FloatEqual(float a, float b)
    {
        if ((a - b > -0.000001) && (a - b) < 0.000001)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    /// 
    /// Get Today data str
    /// 
    /// 
    public static string GetTodayDataStr()
    {
        string timeStr = DateTime.Now.ToString("yyyy-MM-dd");
        return timeStr;
    }
    /// 
    /// Open Browser Url
    /// 
    /// 
    public static void OpenBrowserUrl(string _url)
    {
        Application.OpenURL(_url);
    }
}