#pragma once

#include "TypeDef.h"

#include "bx/filepath.h"

struct WriteBuffer
{
    char* Data = nullptr;
    uint64_t WrittenBytes = 0;
};

struct CppFileWriter
{
  private:
    static constexpr size_t BufferRequestSize = 1024 * 1024 * 1024;
    WriteBuffer HeaderWrite;
    WriteBuffer CppWrite;
    void InitBuffer(WriteBuffer& buf);
    bool WriteBufferToDisk(const bx::FilePath& path, const WriteBuffer& buf);
    void WriteInternal(WriteBuffer& buf, const char* templateStr, va_list args);

  public:
    void PrintTypeName(char* buf, int32_t bufSize, const Def::FieldType& type, const Def::DefinitionFile& definitions);
    void WriteEnums(const Def::DefinitionFile& definitions);
    void WriteTypes(const Def::DefinitionFile& definitions);
    void WriteSaveLoadMethods(const Def::DefinitionFile& definitions);

    void GenerateCpp(const bx::FilePath& outDir, const Def::DefinitionFile& definitions);
    void Write(const char* templateStr, ...);
    void WriteCpp(const char* templateStr, ...);
    void WriteTypeDataFile(const bx::FilePath& outDir, const Def::DefinitionFile& definitions);
};
