// vim:fileencoding=utf-8:foldmethod=marker

#ifndef FILE_H
#define FILE_H

#include "../../common/aliases/aliases.h"
#include "../../base/strings/str8/str8.h"
#include <stdio.h>

#ifdef WAPP_PLATFORM_CPP
BEGIN_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP

typedef FILE File;

typedef enum {
  WAPP_FA_MODE_R,      // Equivalent to r
  WAPP_FA_MODE_W,      // Equivalent to w
  WAPP_FA_MODE_A,      // Equivalent to a
  WAPP_FA_MODE_R_EX,   // Equivalent to r+
  WAPP_FA_MODE_W_EX,   // Equivalent to w+
  WAPP_FA_MODE_A_EX,   // Equivalent to a+
  WAPP_FA_MODE_RB,     // Equivalent to rb
  WAPP_FA_MODE_WB,     // Equivalent to wb
  WAPP_FA_MODE_AB,     // Equivalent to ab
  WAPP_FA_MODE_RB_EX,  // Equivalent to rb+
  WAPP_FA_MODE_WB_EX,  // Equivalent to wb+
  WAPP_FA_MODE_AB_EX,  // Equivalent to ab+
  WAPP_FA_MODE_WX,     // Equivalent to wx
  WAPP_FA_MODE_WX_EX,  // Equivalent to wx+
  WAPP_FA_MODE_WBX,    // Equivalent to wbx
  WAPP_FA_MODE_WBX_EX, // Equivalent to wbx+

  FILE_ACCESS_MODE_COUNT,
} FileAccessMode;

typedef enum {
  WAPP_SEEK_START   = SEEK_SET,
  WAPP_SEEK_CURRENT = SEEK_CUR,
  WAPP_SEEK_END     = SEEK_END,
} FileSeekOrigin;

File *wapp_file_open(Str8RO *filename, FileAccessMode mode);
u64   wapp_file_get_current_position(File *file);
i32   wapp_file_seek(File *file, u64 offset, FileSeekOrigin origin);
u64   wapp_file_get_length(File *file);
u64   wapp_file_read(GenericArray *dst_buf, File *file, u64 item_count);
u64   wapp_file_write(const GenericArray *src_buf, File *file, u64 item_count);
i32   wapp_file_flush(File *file);
i32   wapp_file_close(File *file);

#ifdef WAPP_PLATFORM_CPP
END_C_LINKAGE
#endif // !WAPP_PLATFORM_CPP

#endif // !FILE_H
