using UnityEngine;

namespace Saver
{
    public static class SaveManager
    {
        private const string dataKey = "GameData";

        public static Managers.GameData Load()
        {
            var jsonData = PlayerPrefs.GetString(dataKey, "");

            var data = Newtonsoft.Json.JsonConvert.DeserializeObject<Managers.GameData>(jsonData);
            data ??= new Managers.GameData();

            return data;
        }

        public static void Save(Managers.GameData data)
        {
            var dataJson = Newtonsoft.Json.JsonConvert.SerializeObject(data);
            PlayerPrefs.SetString(dataKey, dataJson);
        }

        public static void ResetProgress()
        {
            PlayerPrefs.DeleteKey(dataKey);
        }
    }
}