#ifndef FILESERVER_DATA_INTERNAL_HXX
#define FILESERVER_DATA_INTERNAL_HXX

#include <filesystem>
#include <cstdio>
#include <spdlog/spdlog.h>
#include "data.hxx"
#include "../util/crash.hxx"

extern std::shared_ptr<spdlog::logger> data_logger;

static constexpr std::string data_new_file = "data.new.json";
static constexpr std::string data_cur_file = "data.json";
static constexpr std::string data_old_file = "data.old.json";

struct SaveNode {
    std::unique_ptr<Node> node;
    std::uint64_t id, parent_id;
    std::list<std::uint64_t> children_ids;
};

struct FileWrapper {
    FileWrapper(const char *file, const char *mode) {
        f = std::fopen(file, mode);
    }

    ~FileWrapper() {
        std::fclose(f);
    }

    std::FILE *f;
};

#endif //FILESERVER_DATA_INTERNAL_HXX
