-module(content_type). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([to_string/1]). -export_type([application_content_type/0, webm_audio_codec/0, audio_content_type/0, font_content_type/0, example_content_type/0, image_content_type/0, message_content_type/0, model_content_type/0, multipart_content_type/0, text_content_type/0, webm_video_codec/0, video_content_type/0, content_type/0]). -type application_content_type() :: json_application_content_type | xml_application_content_type | ogg_application_content_type | {ogg_with_codecs_application_content_type, list(binary())} | {custom_application_content_type, binary()}. -type webm_audio_codec() :: vorbis_webm_audio_codec | opuswebm_audio_codec. -type audio_content_type() :: aac_audio_content_type | flac_audio_content_type | mpeg_audio_content_type | mp3_audio_content_type | webm_audio_content_type | {webm_with_codecs_audio_content_type, list(webm_audio_codec())} | {custom_audio_content_type, binary()}. -type font_content_type() :: collection_font_content_type | otf_font_content_type | sfnt_font_content_type | ttf_font_content_type | woff_font_content_type | woff2_font_content_type | {custom_font_content_type, binary()}. -type example_content_type() :: {custom_example_content_type, binary()}. -type image_content_type() :: jpeg_image_content_type | png_image_content_type | {custom_image_content_type, binary()}. -type message_content_type() :: http_message_content_type | sip_message_content_type | {custom_message_content_type, binary()}. -type model_content_type() :: step_model_content_type | obj_model_content_type | {custom_model_content_type, binary()}. -type multipart_content_type() :: form_data_multipart_content_type | mixed_multipart_content_type | {custom_multipart_content_type, binary()}. -type text_content_type() :: plain_text_content_type | html_text_content_type | javascript_text_content_type | css_text_content_type | {custom_text_content_type, binary()}. -type webm_video_codec() :: vp8webm_video_codec | vp80webm_video_codec. -type video_content_type() :: raw_video_content_type | mp4_video_content_type | mpv_video_content_type | webm_video_content_type | {webm_with_codecs_video_content_type, list(webm_video_codec())} | {custom_video_content_type, binary()}. -type content_type() :: {application_content_type, application_content_type()} | {application_with_codecs_content_type, application_content_type(), list(binary())} | {audio_content_type, audio_content_type()} | {audio_with_codecs_content_type, audio_content_type(), list(binary())} | {font_content_type, font_content_type()} | {example_content_type, example_content_type()} | {image_content_type, image_content_type()} | {message_content_type, message_content_type()} | {model_content_type, model_content_type()} | {multipart_content_type, multipart_content_type()} | {text_content_type, text_content_type()} | {video_content_type, video_content_type()} | {video_with_codecs_content_type, video_content_type(), list(binary())} | {custom_content_type, binary(), binary()} | {custom_raw_content_type, binary()}. -spec codecs_to_string(list(binary())) -> binary(). codecs_to_string(Codecs) -> <<<<"; codecs=\""/utf8, (gleam@string:join(Codecs, <<", "/utf8>>))/binary>>/binary, "\""/utf8>>. -spec application_to_string(application_content_type()) -> binary(). application_to_string(Ct) -> case Ct of json_application_content_type -> <<"json"/utf8>>; xml_application_content_type -> <<"xml"/utf8>>; ogg_application_content_type -> <<"ogg"/utf8>>; {ogg_with_codecs_application_content_type, C} -> <<"ogg"/utf8, (codecs_to_string(C))/binary>>; {custom_application_content_type, S} -> S end. -spec webm_audio_codec_to_string(webm_audio_codec()) -> binary(). webm_audio_codec_to_string(C) -> case C of vorbis_webm_audio_codec -> <<"vorbis"/utf8>>; opuswebm_audio_codec -> <<"opus"/utf8>> end. -spec audio_to_string(audio_content_type()) -> binary(). audio_to_string(Ct) -> case Ct of aac_audio_content_type -> <<"aac"/utf8>>; flac_audio_content_type -> <<"flac"/utf8>>; mpeg_audio_content_type -> <<"mpeg"/utf8>>; mp3_audio_content_type -> <<"mp3"/utf8>>; webm_audio_content_type -> <<"webm"/utf8>>; {webm_with_codecs_audio_content_type, C} -> <<"webm"/utf8, (codecs_to_string( gleam@list:map(C, fun webm_audio_codec_to_string/1) ))/binary>>; {custom_audio_content_type, S} -> S end. -spec font_to_string(font_content_type()) -> binary(). font_to_string(Ct) -> case Ct of collection_font_content_type -> <<"collection"/utf8>>; otf_font_content_type -> <<"otf"/utf8>>; sfnt_font_content_type -> <<"sfnt"/utf8>>; ttf_font_content_type -> <<"ttf"/utf8>>; woff_font_content_type -> <<"woff"/utf8>>; woff2_font_content_type -> <<"woff2"/utf8>>; {custom_font_content_type, S} -> S end. -spec example_to_string(example_content_type()) -> binary(). example_to_string(Ct) -> case Ct of {custom_example_content_type, S} -> S end. -spec image_to_string(image_content_type()) -> binary(). image_to_string(Ct) -> case Ct of jpeg_image_content_type -> <<"jpeg"/utf8>>; png_image_content_type -> <<"png"/utf8>>; {custom_image_content_type, S} -> S end. -spec message_to_string(message_content_type()) -> binary(). message_to_string(Ct) -> case Ct of http_message_content_type -> <<"http"/utf8>>; sip_message_content_type -> <<"sip"/utf8>>; {custom_message_content_type, S} -> S end. -spec model_to_string(model_content_type()) -> binary(). model_to_string(Ct) -> case Ct of step_model_content_type -> <<"step"/utf8>>; obj_model_content_type -> <<"obj"/utf8>>; {custom_model_content_type, S} -> S end. -spec multipart_to_string(multipart_content_type()) -> binary(). multipart_to_string(Ct) -> case Ct of form_data_multipart_content_type -> <<"form-data"/utf8>>; mixed_multipart_content_type -> <<"mixed"/utf8>>; {custom_multipart_content_type, S} -> S end. -spec text_to_string(text_content_type()) -> binary(). text_to_string(Ct) -> case Ct of plain_text_content_type -> <<"plain"/utf8>>; html_text_content_type -> <<"html"/utf8>>; javascript_text_content_type -> <<"javascript"/utf8>>; css_text_content_type -> <<"css"/utf8>>; {custom_text_content_type, S} -> S end. -spec webm_video_codec_to_string(webm_video_codec()) -> binary(). webm_video_codec_to_string(C) -> case C of vp8webm_video_codec -> <<"vp8"/utf8>>; vp80webm_video_codec -> <<"vp8.0"/utf8>> end. -spec video_to_string(video_content_type()) -> binary(). video_to_string(Ct) -> case Ct of raw_video_content_type -> <<"raw"/utf8>>; mp4_video_content_type -> <<"mp4"/utf8>>; mpv_video_content_type -> <<"MPV"/utf8>>; webm_video_content_type -> <<"webm"/utf8>>; {webm_with_codecs_video_content_type, C} -> <<"webm"/utf8, (codecs_to_string( gleam@list:map(C, fun webm_video_codec_to_string/1) ))/binary>>; {custom_video_content_type, S} -> S end. -spec mime(binary(), binary()) -> binary(). mime(Media_type, Sub_type) -> <<<>/binary, Sub_type/binary>>. -spec to_string(content_type()) -> binary(). to_string(Content_type) -> case Content_type of {application_content_type, Ct} -> mime(<<"application"/utf8>>, application_to_string(Ct)); {application_with_codecs_content_type, Ct@1, Cd} -> <<(mime(<<"application"/utf8>>, application_to_string(Ct@1)))/binary, (codecs_to_string(Cd))/binary>>; {audio_content_type, Ct@2} -> mime(<<"audio"/utf8>>, audio_to_string(Ct@2)); {audio_with_codecs_content_type, Ct@3, Cd@1} -> <<(mime(<<"audio"/utf8>>, audio_to_string(Ct@3)))/binary, (codecs_to_string(Cd@1))/binary>>; {font_content_type, Ct@4} -> mime(<<"font"/utf8>>, font_to_string(Ct@4)); {example_content_type, Ct@5} -> mime(<<"example"/utf8>>, example_to_string(Ct@5)); {image_content_type, Ct@6} -> mime(<<"image"/utf8>>, image_to_string(Ct@6)); {message_content_type, Ct@7} -> mime(<<"message"/utf8>>, message_to_string(Ct@7)); {model_content_type, Ct@8} -> mime(<<"model"/utf8>>, model_to_string(Ct@8)); {multipart_content_type, Ct@9} -> mime(<<"multipart"/utf8>>, multipart_to_string(Ct@9)); {text_content_type, Ct@10} -> mime(<<"text"/utf8>>, text_to_string(Ct@10)); {video_content_type, Ct@11} -> mime(<<"video"/utf8>>, video_to_string(Ct@11)); {video_with_codecs_content_type, Ct@12, Cd@2} -> <<(mime(<<"video"/utf8>>, video_to_string(Ct@12)))/binary, (codecs_to_string(Cd@2))/binary>>; {custom_content_type, Mt, St} -> mime(Mt, St); {custom_raw_content_type, S} -> S end.