-module(discord_gleam@ws@packets@message). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/discord_gleam/ws/packets/message.gleam"). -export([string_to_data/1]). -export_type([message_packet_data/0, message_packet/0]). -type message_packet_data() :: {message_packet_data, binary(), binary(), gleam@option:option(binary()), binary(), discord_gleam@types@user:user()}. -type message_packet() :: {message_packet, binary(), integer(), integer(), message_packet_data()}. -file("src/discord_gleam/ws/packets/message.gleam", 23). -spec string_to_data(binary()) -> {ok, message_packet()} | {error, gleam@json:decode_error()}. string_to_data(Encoded) -> Decoder = begin gleam@dynamic@decode:field( <<"t"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(T) -> gleam@dynamic@decode:field( <<"s"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(S) -> gleam@dynamic@decode:field( <<"op"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_int/1}, fun(Op) -> gleam@dynamic@decode:field( <<"d"/utf8>>, begin gleam@dynamic@decode:field( <<"content"/utf8>>, {decoder, fun gleam@dynamic@decode:decode_string/1}, fun(Content) -> gleam@dynamic@decode:field( <<"id"/utf8>>, discord_gleam@discord@snowflake:decoder( ), fun(Id) -> gleam@dynamic@decode:optional_field( <<"guild_id"/utf8>>, none, begin _pipe = discord_gleam@discord@snowflake:decoder( ), gleam@dynamic@decode:map( _pipe, fun(Field@0) -> {some, Field@0} end ) end, fun(Guild_id) -> gleam@dynamic@decode:field( <<"channel_id"/utf8>>, discord_gleam@discord@snowflake:decoder( ), fun( Channel_id ) -> gleam@dynamic@decode:field( <<"author"/utf8>>, discord_gleam@types@user:from_json_decoder( ), fun( Author ) -> gleam@dynamic@decode:success( {message_packet_data, Content, Id, Guild_id, Channel_id, Author} ) end ) end ) end ) end ) end ) end, fun(D) -> gleam@dynamic@decode:success( {message_packet, T, S, Op, D} ) end ) end ) end ) end ) end, gleam@json:parse(Encoded, Decoder).