#ifndef _MY_WIFI_H
#define _MY_WIFI_H

#include <Arduino.h>
#include <ESPAsyncWebServer.h>
#include <ArduinoJson.h>

extern int RebootSystem;

void Wifi_Start_WebServer(void);
void Init_Wifi_Task(void);
void Wifi_Start_MDNS(void);
void Wifi_Task(void *parameters);
String getSoftAPMacAddress(void);
//void onWiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info);
void onWiFiEvent(WiFiEvent_t event);
void Wifi_Request_Task(void *parameters);
void Setup_WebServer_Handlers(AsyncWebServer* serv);

void Wifi_Read_Credentials(const JsonObject &credJson);
void Wifi_Save_Credentials(String newSSID, String newPass);
bool isInternetConnected(void);
void Wifi_Client_Loop(void);

// Handlers
void handlePOST_RegStick(AsyncWebServerRequest *request);

void handleGET_DSLRBooth(AsyncWebServerRequest *request);
void handlePOST_Upload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);
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_SendFile(AsyncWebServerRequest *request);
void onFileUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final);

void handleGET_Get(AsyncWebServerRequest *request);
void handlePOST_Post(AsyncWebServerRequest *request);
void postFileUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final);
void postBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total);


void sendHtmlFile(const char* filePath, AsyncWebServerRequest *request, String (*callback)(const String&));  
String htmlProcessor(const String& var);
String HomeHtmlProcessor(const String& var);
//const char* htmlProcessor(const char* var);
String listDir(fs::FS &fs, const char *dirname, bool isSubdirectory);

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

String varReplace(const String& input, String (*callback)(const String&));
//const char* varReplace(const char* input, const char* (*callback)(const char*));

void CreateSysSummmaryPacket(JsonDocument &doc);







#endif