29 lines
850 B
Gleam
29 lines
850 B
Gleam
import birl.{type Time}
|
|
import gleam/dynamic.{type Dynamic}
|
|
import gleam/dynamic/decode.{type Decoder}
|
|
import gleam/option.{type Option}
|
|
import spacetraders_models/agent_event_id.{type AgentEventId}
|
|
import spacetraders_sdk/internal/time
|
|
|
|
pub type AgentEvent {
|
|
AgentEvent(
|
|
id: AgentEventId,
|
|
type_: String,
|
|
message: String,
|
|
data: Option(Dynamic),
|
|
created_at: Time,
|
|
)
|
|
}
|
|
|
|
pub fn decoder() -> Decoder(AgentEvent) {
|
|
use id <- decode.field("id", agent_event_id.decoder())
|
|
use type_ <- decode.field("type", decode.string)
|
|
use message <- decode.field("message", decode.string)
|
|
use data <- decode.optional_field(
|
|
"data",
|
|
option.None,
|
|
decode.optional(decode.dynamic),
|
|
)
|
|
use created_at <- decode.field("createdAt", time.datetime_decoder())
|
|
decode.success(AgentEvent(id:, type_:, message:, data:, created_at:))
|
|
}
|