/******************************************************************************
*	File		-	helpers.h
*	Author		-	Joey Pollack
*	Date		-	2021/08/30 (y/m/d)
*	Mod Date	-	2021/08/30 (y/m/d)
*	Description	-	Defines some helper methods for use through out the engine.
******************************************************************************/

#ifndef HELPERS_H_
#define HELPERS_H_

#include <core/common_defs.h>
#include <core/types.h>
#include <LunariumConfig.h>
#include <string>
#include <vector>
#include <filesystem>

namespace lunarium
{
    class System
    {
    public:
        static Sizei GetScreenResolution();
        static std::string GetGLSLVersionString();
    };

    class FileSystem
    {
    public:
        static std::vector<std::string> GetFilesInDirectory(std::string path);
        static bool MakeDir(std::string path);


        // Dialog Wrappers
        enum DialogResult
        {
            ERROR,
            OK,
            CANCEL,
        };

        struct FilterItem
        {
            const char* name;
            const char* spec;
        };

        static DialogResult SaveFileDialog(std::filesystem::path& outPath, const FilterItem* filters = nullptr, 
                                            u32 num_filters = 0, const u8* default_path = nullptr, const u8* default_name = nullptr);

        static DialogResult OpenFileDialog(std::filesystem::path& outPath, const FilterItem* filters = nullptr, 
                                            u32 num_filters = 0, const u8* default_path = nullptr);
        
        static DialogResult PickDirectory(std::filesystem::path& outPath, const u8* default_path = nullptr);
        static std::string GetError();
    };

    class Math
    {
    public:
        static int ClampI(int value, int min, int max);
        static float ClampF(float value, float min, float max);
    };

    class String
    {
    public:
    	
        // Splits the string based on the given delimiter,
		// maxSplit = -1 for unlimited number of splits
		static std::vector<std::string> Split(std::string str, char delim = ' ', int maxSplits = -1);

		// Trim given delimiters from start and end of string
		static std::string Trim(std::string str, std::string delims = " \r\n\t");

		// Trim given delimiters from start of string
		static std::string TrimStart(std::string str, std::string delims = " \r\n\t");

		// Trim given delimiters from end of string
		static std::string TrimEnd(std::string str, std::string delims);

        static std::string AsString(int value);
        static std::string AsString(bool value);
        static std::string AsString(float value);

        static std::string StringToUpper(std::string str);
        static std::string StringToLower(std::string str);

        static std::string GetFileNameFromPath(std::string path, bool includeExt);
        static std::string TrimFileNameFromPath(std::string path);
        static std::string GetFileExtension(std::string filename);
    };
}

#endif // HELPERS_H_