using System.IO;
using UnityEngine;

public static class SaveSystem
{
    private static string savePath = Application.persistentDataPath + "/save.json";

    public static void Save(SaveData data)
    {
        string json = JsonUtility.ToJson(data, true);
        File.WriteAllText(savePath, json);
    }

    public static SaveData Load()
    {
        string path = Application.persistentDataPath + "/save.json";

        if (File.Exists(path))
        {
            string json = File.ReadAllText(path);
            return JsonUtility.FromJson<SaveData>(json);
        }
        return null;
    }

    /*public static void SaveGame(SaveData saveData)
    {
        // Save existing player/world data here...

        // Save enemies
        saveData.enemies.Clear();
        Enemy[] enemies = GameObject.FindObjectsOfType<Enemy>();
        foreach (var enemy in enemies)
        {
            saveData.enemies.Add(enemy.GetSaveData());
        }

        SaveSystem.Save(saveData);
    }

    public static void LoadEnemies(SaveData saveData)
    {
        Enemy[] enemies = GameObject.FindObjectsOfType<Enemy>();

        foreach (var enemy in enemies)
        {
            // find matching enemy by ID
            EnemyData data = saveData.enemies.Find(e => e.id == enemy.enemyID);
            if (data != null)
            {
                enemy.LoadData(data);
            }
        }
    }*/


}

