#pragma once

#include <FS.h>
#include <LittleFS.h>
#include <SD.h>
#include <ESPAsyncWebServer.h>

extern volatile bool InternetAvailable;

void Wifi_Init(void);
void Wifi_Load_Settings(String path);
void Wifi_Scan_for_Networks(void);
void Wifi_Start_MDNS(void);
void onWiFiEvent(WiFiEvent_t event);
bool Wifi_Save_Credentials(String path);
void Setup_WebServer_Handlers(AsyncWebServer& serv);

void handlePOST_Update(AsyncWebServerRequest *request);
void updateCallback(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
void updateFirmwareProgress(size_t progress, size_t total);

void handleGET_Query(AsyncWebServerRequest *request);

void handleFilesUpload_OnBody(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);

void sendHtmlFile(const char* filePath, AsyncWebServerRequest *request, String (*callback)(const String&));  
String fileManagerHtmlProcessor(const String& var);
String HomeHtmlProcessor(const String& var);
String listDirAsHtml(String directoryList[], int count);

const char* getFileExtension(const char* filename);
const char* getFileType(const char* ext);
const char* convertFileSize(const size_t bytes);
bool writeFile(fs::FS &fs, const char *path, const char *message);
char* readFile(fs::FS &fs, const char *path);

String varReplace(const String& input, String (*callback)(const String&));
String getSoftAPMacAddress(void);

void Wifi_ConnectTask(void* parameter);
void Wifi_Check_Internet(void);
bool StartWifiConnectTask(String ssid, String pass);
