package org.project.utils;

import org.project.GameState;
import java.io.*;

public class SaveLoadManager {

    public static void saveGame(GameState gameState, String filename) {
        try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(filename))) {
            oos.writeObject(gameState);
            System.out.println("\u001B[34m\u2714\u001B[0m Game saved successfully.");
        } catch (IOException e) {
            System.out.println("\u001B[31m\u2716\u001B[0m Error saving game: " + e.getMessage());
        }
    }

    public static GameState loadGame(String filename) {
        try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(filename))) {
            GameState loadedState = (GameState) ois.readObject();
            System.out.println("\u001B[32m\u2714\u001B[0m Game loaded successfully.");
            return loadedState;
        } catch (IOException | ClassNotFoundException e) {
            System.out.println("\u001B[31m\u2716\u001B[0m Error loading game: " + e.getMessage());
            return null;
        }
    }
}