-module(handles@internal@ctx_utils). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([drill_ctx/2, get_property/3, get_list/3, get_bool/3]). -spec drill_ctx(list(binary()), handles@ctx:value()) -> {ok, handles@ctx:value()} | {error, handles@error:runtime_error()}. drill_ctx(Path, Ctx) -> case Path of [] -> {ok, Ctx}; [Key | Rest] -> case Ctx of {dict, Arr} -> case gleam@list:find( Arr, fun(It) -> erlang:element(2, It) =:= Key end ) of {ok, {prop, _, Value}} -> drill_ctx(Rest, Value); {error, _} -> {error, {unknown_property_error, 0, []}} end; {list, _} -> {error, {unexpected_type_error, 0, [], <<"List"/utf8>>, [<<"Dict"/utf8>>]}}; {str, _} -> {error, {unexpected_type_error, 0, [], <<"Str"/utf8>>, [<<"Dict"/utf8>>]}}; {int, _} -> {error, {unexpected_type_error, 0, [], <<"Int"/utf8>>, [<<"Dict"/utf8>>]}}; {float, _} -> {error, {unexpected_type_error, 0, [], <<"Float"/utf8>>, [<<"Dict"/utf8>>]}}; {bool, _} -> {error, {unexpected_type_error, 0, [], <<"Bool"/utf8>>, [<<"Dict"/utf8>>]}} end end. -spec get_property(integer(), list(binary()), handles@ctx:value()) -> {ok, binary()} | {error, handles@error:runtime_error()}. get_property(Index, Path, Root_ctx) -> _pipe = drill_ctx(Path, Root_ctx), _pipe@1 = gleam@result:map_error(_pipe, fun(Err) -> case Err of {unexpected_type_error, _, _, Got, Expected} -> {unexpected_type_error, Index, Path, Got, Expected}; {unknown_property_error, _, _} -> {unknown_property_error, Index, Path} end end), gleam@result:'try'(_pipe@1, fun(It) -> case It of {str, Value} -> _pipe@2 = Value, {ok, _pipe@2}; {int, Value@1} -> _pipe@3 = Value@1, _pipe@4 = gleam@int:to_string(_pipe@3), {ok, _pipe@4}; {float, Value@2} -> _pipe@5 = Value@2, _pipe@6 = gleam@float:to_string(_pipe@5), {ok, _pipe@6}; {list, _} -> {error, {unexpected_type_error, Index, Path, <<"List"/utf8>>, [<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]}}; {dict, _} -> {error, {unexpected_type_error, Index, Path, <<"Dict"/utf8>>, [<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]}}; {bool, _} -> {error, {unexpected_type_error, Index, Path, <<"Bool"/utf8>>, [<<"Str"/utf8>>, <<"Int"/utf8>>, <<"Float"/utf8>>]}} end end). -spec get_list(integer(), list(binary()), handles@ctx:value()) -> {ok, list(handles@ctx:value())} | {error, handles@error:runtime_error()}. get_list(Index, Path, Root_ctx) -> _pipe = drill_ctx(Path, Root_ctx), _pipe@1 = gleam@result:map_error(_pipe, fun(Err) -> case Err of {unexpected_type_error, _, _, Got, Expected} -> {unexpected_type_error, Index, Path, Got, Expected}; {unknown_property_error, _, _} -> {unknown_property_error, Index, Path} end end), gleam@result:'try'(_pipe@1, fun(It) -> case It of {list, Value} -> _pipe@2 = Value, {ok, _pipe@2}; {bool, _} -> {error, {unexpected_type_error, Index, Path, <<"Bool"/utf8>>, [<<"List"/utf8>>]}}; {str, _} -> {error, {unexpected_type_error, Index, Path, <<"Str"/utf8>>, [<<"List"/utf8>>]}}; {int, _} -> {error, {unexpected_type_error, Index, Path, <<"Int"/utf8>>, [<<"List"/utf8>>]}}; {float, _} -> {error, {unexpected_type_error, Index, Path, <<"Float"/utf8>>, [<<"List"/utf8>>]}}; {dict, _} -> {error, {unexpected_type_error, Index, Path, <<"Dict"/utf8>>, [<<"List"/utf8>>]}} end end). -spec get_bool(integer(), list(binary()), handles@ctx:value()) -> {ok, boolean()} | {error, handles@error:runtime_error()}. get_bool(Index, Path, Root_ctx) -> _pipe = drill_ctx(Path, Root_ctx), _pipe@1 = gleam@result:map_error(_pipe, fun(Err) -> case Err of {unexpected_type_error, _, _, Got, Expected} -> {unexpected_type_error, Index, Path, Got, Expected}; {unknown_property_error, _, _} -> {unknown_property_error, Index, Path} end end), gleam@result:'try'(_pipe@1, fun(It) -> case It of {bool, Value} -> _pipe@2 = Value, {ok, _pipe@2}; {list, _} -> {error, {unexpected_type_error, Index, Path, <<"List"/utf8>>, [<<"Bool"/utf8>>]}}; {str, _} -> {error, {unexpected_type_error, Index, Path, <<"Str"/utf8>>, [<<"Bool"/utf8>>]}}; {int, _} -> {error, {unexpected_type_error, Index, Path, <<"Int"/utf8>>, [<<"Bool"/utf8>>]}}; {float, _} -> {error, {unexpected_type_error, Index, Path, <<"Float"/utf8>>, [<<"Bool"/utf8>>]}}; {dict, _} -> {error, {unexpected_type_error, Index, Path, <<"Dict"/utf8>>, [<<"Bool"/utf8>>]}} end end).