#pragma once

#include "FileFormats.h"

#include <filesystem>
#include <string>
#include <fstream>
#include <memory>
#include <vector>
#include <optional>

using Path = std::filesystem::path;

class File
{
public:
    enum class AccessMode{
        Read,
        Write
    };

public:
    File(std::filesystem::path fullPath);

    ~File();

    void close();

    std::string dumpBinary();

    std::string getExtension() const;

    std::ifstream* getInHandle() const;

    std::ofstream* getOutHandle() const;

    FileFormat::Format inferFormat() const;

    std::string readText();

    std::vector<std::string> readLines();

    std::string read();

    bool pathExists() const;

    bool open(AccessMode mode);

    std::optional<unsigned char> readNextByte();

    void writeText(const std::string& text);

private:
    std::filesystem::path mFullPath;
    std::unique_ptr<std::ifstream> mInHandle;
    std::unique_ptr<std::ofstream> mOutHandle;
};
