#ifndef MIME_TYPES_H
#define MIME_TYPES_H

#include <string>
#include <array>

struct MimeType {
    std::string mimeType;
    std::string extension;
    std::array<unsigned char, 8> magic;
    size_t magicSize;
};

const MimeType MIME_TYPES[] = {
    // Images
    {
        "image/png",
        ".png",
        {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A},
        8
    },
    {
        "image/jpeg",
        ".jpg",
        {0xFF, 0xD8, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00},
        3
    },
    {
        "image/gif",
        ".gif",
        {0x47, 0x49, 0x46, 0x38, 0x37, 0x61, 0x00, 0x00},
        6
    },
    {
        "image/gif",
        ".gif",
        {0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x00, 0x00},
        6
    },
    {
        "image/webp",
        ".webp",
        {0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00},
        4
    },
    {
        "image/bmp",
        ".bmp",
        {0x42, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        2
    },
    {
        "image/tiff",
        ".tiff",
        {0x49, 0x49, 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00},
        4
    },
    {
        "image/x-icon",
        ".ico",
        {0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00},
        4
    },

    // Documents
    {
        "application/pdf",
        ".pdf",
        {0x25, 0x50, 0x44, 0x46, 0x2D, 0x00, 0x00, 0x00},
        5
    },
    {
        "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        ".docx",
        {0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00},
        8
    },
    {
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        ".xlsx",
        {0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00},
        8
    },
    {
        "application/vnd.openxmlformats-officedocument.presentationml.presentation",
        ".pptx",
        {0x50, 0x4B, 0x03, 0x04, 0x14, 0x00, 0x06, 0x00},
        8
    },

    // Archives
    {
        "application/zip",
        ".zip",
        {0x50, 0x4B, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00},
        4
    },
    {
        "application/x-rar-compressed",
        ".rar",
        {0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00, 0x00},
        7
    },
    {
        "application/x-7z-compressed",
        ".7z",
        {0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C, 0x00, 0x00},
        6
    },
    {
        "application/gzip",
        ".gz",
        {0x1F, 0x8B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00},
        3
    },

    // Audio/Video
    {
        "audio/mpeg",
        ".mp3",
        {0x49, 0x44, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00},
        3
    },
    {
        "video/mp4",
        ".mp4",
        {0x66, 0x74, 0x79, 0x70, 0x69, 0x73, 0x6F, 0x6D},
        8
    },
    {
        "audio/wav",
        ".wav",
        {0x52, 0x49, 0x46, 0x46, 0x00, 0x00, 0x00, 0x00},
        4
    },
    {
        "video/x-matroska",
        ".mkv",
        {0x1A, 0x45, 0xDF, 0xA3, 0x00, 0x00, 0x00, 0x00},
        4
    },

    // Web formats
    {
        "text/html",
        ".html",
        {0x3C, 0x21, 0x44, 0x4F, 0x43, 0x54, 0x59, 0x50},
        8
    },
    {
        "text/css",
        ".css",
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        0
    },
    {
        "application/javascript",
        ".js",
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        0
    },
    {
        "application/json",
        ".json",
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        0
    },
    {
        "text/xml",
        ".xml",
        {0x3C, 0x3F, 0x78, 0x6D, 0x6C, 0x20, 0x00, 0x00},
        5
    },
    {
        "application/wasm",
        ".wasm",
        {0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00},
        8
    },
    {
        "text/markdown",
        ".md",
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        0
    },
    {
        "text/csv",
        ".csv",
        {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        0
    },

    // Fonts
    {
        "font/woff",
        ".woff",
        {0x77, 0x4F, 0x46, 0x46, 0x00, 0x01, 0x00, 0x00},
        8
    },
    {
        "font/woff2",
        ".woff2",
        {0x77, 0x4F, 0x46, 0x32, 0x00, 0x01, 0x00, 0x00},
        8
    },
    {
        "font/ttf",
        ".ttf",
        {0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
        4
    },
    {
        "font/otf",
        ".otf",
        {0x4F, 0x54, 0x54, 0x4F, 0x00, 0x00, 0x00, 0x00},
        4
    }
};

bool checkMimeType(const unsigned char* data, size_t length, const MimeType& signature);

#endif // MIME_TYPES_H