#include "mime_types.hpp"


namespace http::server::mime_types {
    struct mapping {
        const char *extension;
        const char *mime_type;
    } mappings[] =
    {
        {"gif", "image/gif"},
        {"htm", "text/html"},
        {"html", "text/html"},
        {"jpg", "image/jpeg"},
        {"png", "image/png"}
    };

    std::string extensionToType(const std::string &extension) {
        for (mapping m: mappings) {
            if (m.extension == extension) {
                return m.mime_type;
            }
        }

        return "text/plain";
    }
} // namespace http::server::mime_types

std::string http::server::mime_types::toString(Mime m) {
    switch (m) {
        case image_gif: return "image/gif";
        case image_png: return "image/png";
        case image_jpeg: return "image/jpeg";
        case image_svg: return "image/svg+xml";
        case image_webp: return "image/webp";
        case image_ico: return "image/vnd.microsoft.icon";
        case text_plain: return "text/plain";
        case text_html: return "text/html";
        case text_css: return "text/css";
        case json: return "application/json";
        case javascript: return "application/javascript";
        case blob:
        default:
            return "application/octet-stream";
    }
}
