-module(telega@models@bot_command). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new_botcommand_parameters/0, decode/1, scope_to_json/1, encode_botcommand_parameters/1, from/1]). -export_type([bot_command/0, bot_command_scope/0, bot_command_parameters/0]). -type bot_command() :: {bot_command, binary(), binary()}. -type bot_command_scope() :: bot_command_default_scope | bot_command_all_private_chats_scope | bot_command_scope_all_group_chats | bot_command_scope_all_chat_administrators | {bot_command_scope_chat, integer()} | {bot_command_scope_chat_string, telega@models@common:int_or_string()} | {bot_command_scope_chat_administrators, telega@models@common:int_or_string()} | {bot_command_scope_chat_member, telega@models@common:int_or_string(), integer()}. -type bot_command_parameters() :: {bot_command_parameters, gleam@option:option(bot_command_scope()), gleam@option:option(binary())}. -spec new_botcommand_parameters() -> bot_command_parameters(). new_botcommand_parameters() -> {bot_command_parameters, none, none}. -spec decode(gleam@dynamic:dynamic_()) -> {ok, list(bot_command())} | {error, list(gleam@dynamic:decode_error())}. decode(Json) -> _pipe = Json, (gleam@dynamic:list( gleam@dynamic:decode2( fun(Field@0, Field@1) -> {bot_command, Field@0, Field@1} end, gleam@dynamic:field(<<"command"/utf8>>, fun gleam@dynamic:string/1), gleam@dynamic:field( <<"description"/utf8>>, fun gleam@dynamic:string/1 ) ) ))(_pipe). -spec scope_to_json(bot_command_scope()) -> gleam@json:json(). scope_to_json(Scope) -> case Scope of bot_command_default_scope -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"default"/utf8>>)}] ); bot_command_all_private_chats_scope -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"all_private_chats"/utf8>>)}] ); bot_command_scope_all_group_chats -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"all_group_chats"/utf8>>)}] ); bot_command_scope_all_chat_administrators -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"all_chat_administrators"/utf8>>)}] ); {bot_command_scope_chat, Chat_id} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"chat"/utf8>>)}, {<<"chat_id"/utf8>>, gleam@json:int(Chat_id)}] ); {bot_command_scope_chat_string, Chat_id@1} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"chat"/utf8>>)}, {<<"chat_id"/utf8>>, telega@models@common:string_or_int_to_json(Chat_id@1)}] ); {bot_command_scope_chat_administrators, Chat_id@2} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"chat_administrators"/utf8>>)}, {<<"chat_id"/utf8>>, telega@models@common:string_or_int_to_json(Chat_id@2)}] ); {bot_command_scope_chat_member, Chat_id@3, User_id} -> gleam@json:object( [{<<"type"/utf8>>, gleam@json:string(<<"chat_member"/utf8>>)}, {<<"chat_id"/utf8>>, telega@models@common:string_or_int_to_json(Chat_id@3)}, {<<"user_id"/utf8>>, gleam@json:int(User_id)}] ) end. -spec encode_botcommand_parameters(bot_command_parameters()) -> list({binary(), gleam@json:json()}). encode_botcommand_parameters(Params) -> Scope@1 = begin _pipe = erlang:element(2, Params), _pipe@1 = gleam@option:map( _pipe, fun(Scope) -> [{<<"scope"/utf8>>, scope_to_json(Scope)}] end ), gleam@option:unwrap(_pipe@1, []) end, Language_code@1 = begin _pipe@2 = erlang:element(3, Params), _pipe@3 = gleam@option:map( _pipe@2, fun(Language_code) -> [{<<"language_code"/utf8>>, gleam@json:string(Language_code)}] end ), gleam@option:unwrap(_pipe@3, []) end, gleam@list:concat([Scope@1, Language_code@1]). -spec from(list({binary(), binary()})) -> list(bot_command()). from(Commands) -> _pipe = Commands, gleam@list:map( _pipe, fun(Command) -> {Command@1, Description} = Command, {bot_command, Command@1, Description} end ).