#pragma once

#include "chunk.h"

#include <string>

// Saves and loads chunks to/from binary files under the save directory.
class WorldSave {
public:
    // Directory where chunk files are stored (default: "save/chunks")
    inline static std::string saveDir = "save/chunks";

    // Returns true if a saved file exists for this chunk position.
    static bool exists(const ChunkPos& pos);

    // Serialize chunk to disk. Creates directories as needed.
    static void save(const Chunk& chunk);

    // Deserialize chunk from disk into an already-constructed Chunk.
    // Returns false if the file doesn't exist or is corrupt.
    static bool load(Chunk& chunk);

private:
    static std::string filePath(const ChunkPos& pos);
};
