-module(telega@dialog@types). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/telega/dialog/types.gleam"). -export([new_store/0, store_get/2, store_set/3, encode_store/1, decode_store/1, default_labels/0]). -export_type([rendered_window/0, dialog_media/0, dialog_button/0, dialog_action/1, action_event/0, window/4, keyboard_widget/4, widget_ctx/4, widget_result/1, widget_store/0, labels/0, dialog_build_error/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " Shared type definitions for the declarative dialog system.\n" "\n" " A dialog is a set of windows; a window is a pure render function plus\n" " event handlers. See `telega/dialog` for the builder API and the full\n" " guide.\n" ). -type rendered_window() :: {rendered_window, telega@format:formatted_text(), list(list(dialog_button())), gleam@option:option(dialog_media())}. -type dialog_media() :: {photo_media, binary(), boolean()} | {video_media, binary(), boolean()} | {animation_media, binary()} | {document_media, binary()}. -type dialog_button() :: {action_button, binary(), binary()} | {action_arg_button, binary(), binary(), binary()} | {url_button, binary(), binary()} | {web_app_button, binary(), binary()} | {noop_button, binary()}. -type dialog_action(AVCT) :: {stay, AVCT} | {goto, binary(), AVCT} | {back, AVCT} | {done, AVCT} | {start_sub, binary(), gleam@dict:dict(binary(), binary()), AVCT}. -type action_event() :: {action_event, binary(), gleam@option:option(binary())}. -type window(AVCU, AVCV, AVCW, AVCX) :: {window, binary(), fun((AVCU, telega@bot:context(AVCV, AVCW, AVCX)) -> rendered_window()), fun((AVCU, action_event(), telega@bot:context(AVCV, AVCW, AVCX)) -> {ok, dialog_action(AVCU)} | {error, AVCW}), gleam@option:option(fun((AVCU, binary(), telega@bot:context(AVCV, AVCW, AVCX)) -> {ok, dialog_action(AVCU)} | {error, AVCW})), list(keyboard_widget(AVCU, AVCV, AVCW, AVCX)), gleam@option:option(fun((AVCU, gleam@dict:dict(binary(), binary()), telega@bot:context(AVCV, AVCW, AVCX)) -> {ok, dialog_action(AVCU)} | {error, AVCW}))}. -type keyboard_widget(AVCY, AVCZ, AVDA, AVDB) :: {keyboard_widget, binary(), fun((widget_ctx(AVCY, AVCZ, AVDA, AVDB)) -> list(list(dialog_button()))), fun((widget_ctx(AVCY, AVCZ, AVDA, AVDB), binary(), gleam@option:option(binary())) -> {ok, widget_result(AVCY)} | {error, AVDA}), list(binary()), list(binary())}. -type widget_ctx(AVDC, AVDD, AVDE, AVDF) :: {widget_ctx, AVDC, widget_store(), labels(), telega@bot:context(AVDD, AVDE, AVDF)}. -type widget_result(AVDG) :: {store_updated, widget_store()} | {emit, dialog_action(AVDG)}. -opaque widget_store() :: {widget_store, gleam@dict:dict(binary(), binary())}. -type labels() :: {labels, binary(), binary(), binary(), binary(), binary(), binary(), binary(), binary(), binary()}. -type dialog_build_error() :: {duplicate_window_id, binary()} | {unknown_window_reference, binary(), binary()} | {callback_data_too_long, binary(), binary(), integer()} | no_windows | {unknown_initial_window, binary()} | {duplicate_widget_id, binary(), binary()} | {reserved_id_character, binary(), binary()} | {duplicate_sub_dialog_id, binary()} | {nested_sub_dialog, binary()}. -file("src/telega/dialog/types.gleam", 170). -spec new_store() -> widget_store(). new_store() -> {widget_store, maps:new()}. -file("src/telega/dialog/types.gleam", 174). -spec store_get(widget_store(), binary()) -> gleam@option:option(binary()). store_get(Store, Key) -> _pipe = gleam_stdlib:map_get(erlang:element(2, Store), Key), gleam@option:from_result(_pipe). -file("src/telega/dialog/types.gleam", 178). -spec store_set(widget_store(), binary(), binary()) -> widget_store(). store_set(Store, Key, Value) -> {widget_store, gleam@dict:insert(erlang:element(2, Store), Key, Value)}. -file("src/telega/dialog/types.gleam", 189). ?DOC(false). -spec encode_store(widget_store()) -> binary(). encode_store(Store) -> _pipe = erlang:element(2, Store), _pipe@1 = maps:to_list(_pipe), _pipe@2 = gleam@list:map( _pipe@1, fun(Entry) -> {erlang:element(1, Entry), gleam@json:string(erlang:element(2, Entry))} end ), _pipe@3 = gleam@json:object(_pipe@2), gleam@json:to_string(_pipe@3). -file("src/telega/dialog/types.gleam", 198). ?DOC(false). -spec decode_store(binary()) -> {ok, widget_store()} | {error, nil}. decode_store(Raw) -> _pipe = gleam@json:parse( Raw, gleam@dynamic@decode:dict( {decoder, fun gleam@dynamic@decode:decode_string/1}, {decoder, fun gleam@dynamic@decode:decode_string/1} ) ), _pipe@1 = gleam@result:map( _pipe, fun(Field@0) -> {widget_store, Field@0} end ), gleam@result:replace_error(_pipe@1, nil). -file("src/telega/dialog/types.gleam", 223). -spec default_labels() -> labels(). default_labels() -> {labels, <<"‹"/utf8>>, <<"›"/utf8>>, <<"{current}/{total}"/utf8>>, <<"● "/utf8>>, <<"○ "/utf8>>, <<"☑ "/utf8>>, <<"☐ "/utf8>>, <<"✓"/utf8>>, <<"⏳"/utf8>>}.