#ifndef _JFXMAP_FILESYS_H_
#define _JFXMAP_FILESYS_H_

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

// #include "log.h"

namespace jf {

class FileSys {
   public:
    template <typename LineFuncType>
    static void ReadByLine(const std::string& f, LineFuncType lf) {
        // jf_log_info("[FileSys::Read] load file {}", f);
        std::ifstream fin(f.c_str());
        std::string l;
        int lineNum = 0;
        while (std::getline(fin, l)) {
            std::istringstream iss(l);
            lf(iss, ++lineNum);
        }
    }

    static bool Exist(const std::string& fullPath);
    static bool Read(const std::string& f, std::string& is, bool encrypt = false);
    static std::vector<std::string> GetAllFiles(const std::string& dir);
    static void Save(const std::string& f, const std::string& content, bool encrypt = false);
    static void AppendSlow(const std::string& f, const std::string& content);
    static void CleanDir(const std::string& dir);
    static void MkDir(const std::string& dir);
    static void Remove(const std::string& path);
    static bool FileNameEndWith(const std::string& fileName, const std::string& ext);
    static std::string ChoosePath(const std::vector<std::string>& dirs, const std::string& subPath);

    static std::string key;
};
}  // namespace jf

#endif  //_JFXMAP_FILESYS_H_