/*

 * Copyright (C) 2026 Huawei Device Co., Ltd.

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *     http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */



#include "media_map_const_utils.h"



#include "userfile_manager_types.h"



namespace OHOS::Media {

static const std::unordered_map<std::string, std::vector<std::string>> MEDIA_MIME_TYPE_MAP = {

    { "application/epub+zip", { "epub" } },

    { "application/lrc", { "lrc"} },

    { "application/pkix-cert", { "cer" } },

    { "application/rss+xml", { "rss" } },

    { "application/sdp", { "sdp" } },

    { "application/smil+xml", { "smil" } },

    { "application/ttml+xml", { "ttml", "dfxp" } },

    { "application/vnd.ms-pki.stl", { "stl" } },

    { "application/vnd.ms-powerpoint", { "pot", "ppt" } },

    { "application/vnd.ms-wpl", { "wpl" } },

    { "application/vnd.stardivision.writer", { "vor" } },

    { "application/vnd.youtube.yt", { "yt" } },

    { "application/x-font", { "pcf" } },

    { "application/x-mobipocket-ebook", { "prc", "mobi" } },

    { "application/x-pem-file", { "pem" } },

    { "application/x-pkcs12", { "p12", "pfx" } },

    { "application/x-subrip", { "srt" } },

    { "application/x-webarchive", { "webarchive" } },

    { "application/x-webarchive-xml", { "webarchivexml" } },

    { "application/pgp-signature", { "pgp" } },

    { "application/x-x509-ca-cert", { "crt", "der" } },

    { "application/json", { "json" } },

    { "application/javascript", { "js" } },

    { "application/zip", { "zip" } },

    { "application/rar", { "rar" } },

    { "application/pdf", { "pdf" } },

    { "application/msword", { "doc" } },

    { "application/ms-excel", { "xls" } },

    { "application/vnd.openxmlformats-officedocument.wordprocessingml.document", { "docx" } },

    { "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", { "xlsx" } },

    { "application/vnd.openxmlformats-officedocument.presentationml.presentation", { "pptx" } },

    { "audio/3gpp", { "3ga" } },

    { "audio/ac3", { "ac3", "a52"} },

    { "audio/amr", { "amr" } },

    { "audio/imelody", { "imy" } },

    { "audio/midi", { "rtttl", "xmf", "rtx" } },

    { "audio/mobile-xmf", { "mxmf"} },

    { "audio/mp4", { "m4a", "m4b", "m4p", "f4a", "f4b", "f4p" } },

    { "audio/mpegurl", { "m3u" } },

    { "audio/sp-midi", { "smf" } },

    { "audio/x-matroska", { "mka" } },

    { "audio/x-pn-realaudio", { "ra" } },

    { "audio/x-mpeg", { "mp3" } },

    { "audio/aac", { "aac", "adts", "adt" } },

    { "audio/basic", { "snd" } },

    { "audio/flac", { "flac" } },

    { "audio/mpeg", { "mp3", "mp2", "mp1", "mpa", "m4r" } },

    { "audio/wav", { "wav" } },

    { "audio/ogg", { "ogg" } },

    { "image/gif", { "gif"} },

    { "image/heic", { "heic" } },

    { "image/heic-sequence", { "heics", "heifs" } },

    { "image/bmp", { "bmp", "bm" } },

    { "image/heif", { "heif", "hif" } },

    { "image/avif", { "avif" } },

    { "image/ico", { "cur" } },

    { "image/webp", { "webp"} },

    { "image/x-adobe-dng", { "dng" } },

    { "image/x-fuji-raf", { "raf" } },

    { "image/x-icon", { "ico" } },

    { "image/x-nikon-nrw", { "nrw" } },

    { "image/x-panasonic-rw2", { "rw2" } },

    { "image/x-pentax-pef", { "pef" } },

    { "image/x-samsung-srw", { "srw" } },

    { "image/x-sony-arw", { "arw" } },

    { "image/jpeg", { "jpg", "jpeg", "jpe" } },

    { "image/png", { "png" } },

    { "image/svg+xml", { "svg", "svgz" } },

    { "image/x-dcraw", { "raw" } },

    { "image/ief", { "ief" } },

    { "image/jp2", { "jp2", "jpg2" } },

    { "image/ipm", { "ipm" } },

    { "image/jpm", { "jpm" } },

    { "image/ipx", { "jpx", "jpf" } },

    { "image/pcx", { "pcx" } },

    { "image/tiff", { "tiff", "tif" } },

    { "image/vnd.divu", { "djvu", "djv" } },

    { "image/vnd.wap.wbmp", { "wbmp" } },

    { "image/x-canon-cr2", { "cr2" } },

    { "image/x-canon-crw", { "crw" } },

    { "image/x-cmu-raster", { "ras" } },

    { "image/x-coreldraw", { "cdr" } },

    { "image/x-coreldrawpattern", { "pat" } },

    { "image/x-coreldrawtemplate", { "cdt" } },

    { "image/x-corelphotopaint", { "cpt" } },

    { "image/x-epson-erf", { "erf" } },

    { "image/x-jg", { "art" } },

    { "image/x-jng", { "jng" } },

    { "image/x-nikon-nef", { "nef" } },

    { "image/x-olvmpus-orf", { "orf" } },

    { "image/x-photoshop", { "psd" } },

    { "image/x-portable-anymap", { "pnm" } },

    { "image/x-portable-bitmap", { "pbm" } },

    { "image/x-portable-graymap", { "pgm" } },

    { "image/x-portable-pixmap", { "ppm" } },

    { "image/x-rgb", { "rgb" } },

    { "image/x-xbitmap", { "xbm" } },

    { "image/x-xpixmap", { "xpm" } },

    { "image/x-xwindowdump", { "xwd" } },

    { "image/mpo", { "mpo" } },

    { "video/3gpp2", { "3gpp2", "3gp2", "3g2" } },

    { "video/3gpp", { "3gpp", "3gp" } },

    { "video/mp4", { "m4v", "f4v", "mp4v", "mpeg4", "mp4" } },

    { "video/mp2t", { "m2ts", "mts"} },

    { "video/mp2ts", { "ts" } },

    { "video/vnd.youtube.yt", { "yt" } },

    { "video/x-webex", { "wrf" } },

    { "video/mpeg", { "mpe", "mpeg", "mpeg2", "mpv2", "mp2v", "m2v", "m2t", "mpeg1", "mpv1", "mp1v", "m1v", "mpg" } },

    { "video/quicktime", { "mov", "qt" } },

    { "video/x-matroska", { "mkv", "mpv" } },

    { "video/webm", { "webm" } },

    { "video/H264", { "h264" } },

    { "video/x-flv", { "flv" } },

    { "video/avi", { "avi" } },

    { "video/x-pn-realvideo", { "rmvb" } },

    { "video/annodex", { "axv" } },

    { "video/dl", { "dl" } },

    { "video/dv", { "dif", "dv" } },

    { "video/fli", { "fli" } },

    { "video/gl", { "gl" } },

    { "video/ogg", { "ogv" } },

    { "video/vnd.mpegurl", { "mxu" } },

    { "video/x-la-asf", { "lsf",  "lsx" } },

    { "video/x-mng", { "mng" } },

    { "video/x-ms-asf", { "asf", "asx" } },

    { "video/x-ms-wm", { "wm" } },

    { "video/x-ms-wmv", { "wmv" } },

    { "video/x-ms-wmx", { "wmx" } },

    { "video/x-ms-wvx", { "wvx" } },

    { "video/x-sgi-movie", { "movie" } },

    { "video/mpg4", { "mpg4" } },

    { "video/rm", { "rm" } },

    { "video/rv", { "rv" } },

    { "video/divx", { "divx" } },

    { "video/m4u", { "m4u" } },

    { "text/comma-separated-values", { "csv" } },

    { "text/plain", { "diff", "po", "txt" } },

    { "text/rtf", { "rtf" } },

    { "text/text", { "phps", "m3u", "m3u8" } },

    { "text/xml", { "xml" } },

    { "text/x-vcard", { "vcf" } },

    { "text/x-c++hdr", { "hpp", "h++", "hxx", "hh" } },

    { "text/x-c++src", { "cpp", "c++", "cxx", "cc" } },

    { "text/css", { "css" } },

    { "text/html", { "html", "htm", "shtml"} },

    { "text/markdown", { "md", "markdown" } },

    { "text/x-java", { "java" } },

    { "text/x-python", { "py" } },

};



const std::unordered_map<std::string, std::vector<std::string>>& MediaMapConstUtils::GetMimeTypeMap()

{

    return MEDIA_MIME_TYPE_MAP;

}



const std::string MediaMapConstUtils::MediaTypeToString(const int32_t mediaType)

{

    static const std::unordered_map<int32_t, std::string> mediaTypeMap = {

        { MediaType::MEDIA_TYPE_FILE, "FILE" },

        { MediaType::MEDIA_TYPE_IMAGE, "IMAGE" },

        { MediaType::MEDIA_TYPE_VIDEO, "VIDEO" },

        { MediaType::MEDIA_TYPE_AUDIO, "AUDIO" },

        { MediaType::MEDIA_TYPE_MEDIA, "MEDIA" },

        { MediaType::MEDIA_TYPE_ALBUM_LIST, "ALBUM_LIST" },

        { MediaType::MEDIA_TYPE_ALBUM_LIST_INFO, "ALBUM_LIST_INFO" },

        { MediaType::MEDIA_TYPE_ALBUM, "ALBUM" },

        { MediaType::MEDIA_TYPE_SMARTALBUM, "SMARTALBUM" },

        { MediaType::MEDIA_TYPE_DEVICE, "DEVICE" },

        { MediaType::MEDIA_TYPE_REMOTEFILE, "REMOTEFILE" },

        { MediaType::MEDIA_TYPE_NOFILE, "NOFILE" },

        { MediaType::MEDIA_TYPE_PHOTO, "PHOTO" },

        { MediaType::MEDIA_TYPE_ALL, "ALL" },

        { MediaType::MEDIA_TYPE_DEFAULT, "DEFAULT" },

    };

    auto it = mediaTypeMap.find(mediaType);

    return it == mediaTypeMap.end() ? "UNKNOWN" : it->second;

}

} // namespace OHOS::Media