using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
using SGModule.Common.Extensions;
using UnityEngine;
namespace RedHotRoast
{
    public class SaveData
    {
        public static Saveobject _saveObject;
        public static Saveobject GetSaveObject()
        {
            if (_saveObject == null)
            {
                // if (File.Exists(jsonFilePath))
                // {
                //     string jsonstr = File.ReadAllText(jsonFilePath);
                //     _saveObject = JsonConvert.DeserializeObject<Saveobject>(jsonstr);
                //     return _saveObject;
                // }
                // else
                // {
                //     _saveObject = new Saveobject();
                //     return _saveObject;
                // }

                _saveObject = DataMgr.SaveObject.Value;
            }


            return _saveObject;

        }

        public static void SaveDataFunc()
        {
            DataMgr.SaveObject.Save();
        }

        public static bool battlepassred()
        {

            int pass_level = GameHelper.GetBattleLv();
            List<int> freelist = SaveData.GetSaveObject().battle_pass_freelist;
            for (int i = 1; i <= ConfigSystem.GetConfig<Passportrewards>().Count; i++)
            {
                if (pass_level >= i)
                {
                    if (!freelist.Contains(i))
                    {
                        return true;
                    }
                }

            }
            if (SaveData.GetSaveObject().is_get_battlepass)
            {
                List<int> paylist = SaveData.GetSaveObject().battle_pass_paylist;
                for (int i = 1; i <= ConfigSystem.GetConfig<Passportrewards>().Count; i++)
                {
                    if (pass_level >= i)
                    {
                        if (!paylist.Contains(i))
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public static bool passtaskred()
        {
            List<int> list = SaveData.GetSaveObject().pass_task_record;
            for (int i = 0; i < ConfigSystem.GetConfig<PassingTask>().Count; i++)
            {
                if (GameHelper.GetLevel() > ConfigSystem.GetConfig<PassingTask>()[i].tol_num)
                {
                    if (!list.Contains(ConfigSystem.GetConfig<PassingTask>()[i].id)) return true;
                }
            }
            return false;
        }
        public static bool timetaskred()
        {
            List<int> list = SaveData.GetSaveObject().time_task_record;
            for (int i = 0; i < ConfigSystem.GetConfig<Durationtasks>().Count; i++)
            {
                if (GameHelper.GetGameTime() >= ConfigSystem.GetConfig<Durationtasks>()[i].tol_num * 60)
                {
                    if (!list.Contains(ConfigSystem.GetConfig<Durationtasks>()[i].id)) return true;
                }
            }
            return false;
        }

        public static bool AdTaskred()
        {
            List<int> list = SaveData.GetSaveObject().ad_task_record;

            for (int i = 0; i < ConfigSystem.GetConfig<ADTask>().Count; i++)
            {
                if (DataMgr.VideoWatchCount.Value >= ConfigSystem.GetConfig<ADTask>()[i].tol_num)
                {
                    if (!list.Contains(ConfigSystem.GetConfig<ADTask>()[i].id)) return true;
                }
            }
            return false;
        }
        public static bool getRed()
        {

            return battlepassred();
        }
        public static float pay_time = 0;
        public static float rm_time = 0;



    }

    public class Saveobject
    {


        public bool is_get_battlepass = false;
        public List<int> battle_pass_freelist = new List<int>();
        public List<int> battle_pass_paylist = new List<int>();



        public int _goldtime0;
        public int _goldtime1;
        public int _goldtime2;
        public int _goldtime3;
        public int _goldtime4;
        public int[] _goldtime;
        public bool have_slot;
        public int battle_pass_time;
        public int _watch_ad_cd;


        public List<int> pass_task_record = new List<int>();
        public List<int> time_task_record = new List<int>();
        public List<int> ad_task_record = new List<int>();

        /// <summary>
        /// 每一局使用道具数量（[0]:out [1]:back [2]:refresh）
        /// </summary>
        public int[] usePropsNum = new int[3];
        /// <summary>
        /// 卡牌层数
        /// </summary>
        public int card_layer;
        /// <summary>
        /// 卡牌总数量
        /// </summary>
        public int all_card_numbers;


        public int login_day;
        public int login_hour;
        public int ch_people;
        public float ch_people_1;
        public float ch_people_2;

        public bool is_get_packreward;

        public bool is_get_removead;
        public bool is_autopack_show;
        public int is_autopack_show_day;

        public long start_time;
        public int clear_number;
        public int remove_ad_time;

        public int this_time_cardtype;

        public int[] dark_Dayref;

        public ApplePayClass max_pay_object;
        public List<SaveingPotClass> saveingpot_history = new List<SaveingPotClass>();
        public float saveingpot_ch;
        public float last_saveingpot_ch;

        public long failed_pack_time;
        public int three_gift_got_index = 1;
        public long last_got_three_gift_time = 0;
        public bool is_get_ThreeDaysGift;
        public string attribution = "null";
        public int watchRewardADnumbers;
        public double watchRewardAD_value;
        public int LargeRewardNum;
        public int InterstitialPLayNum;
        public int TurnOffNumbers;
        public int TurnOffDay;
        public long TurnOffTime;
        
        public int crush_egg_time;
    }
}
