using System.Text.Json;
using System.Text.Json.Serialization;
namespace CarpaNet.Jetstream;
///
/// A Jetstream event envelope containing a repo event with decoded record data.
///
public sealed class JetstreamEvent
{
///
/// The DID of the repo this event belongs to.
///
[JsonPropertyName("did")]
public string Did { get; set; } = string.Empty;
///
/// Unix microseconds timestamp assigned by Jetstream.
///
[JsonPropertyName("time_us")]
public long TimeUs { get; set; }
///
/// The kind of event: "commit", "identity", or "account".
///
[JsonPropertyName("kind")]
public string Kind { get; set; } = string.Empty;
///
/// Commit event data. Present when is "commit".
///
[JsonPropertyName("commit")]
public JetstreamCommit? Commit { get; set; }
///
/// Identity event data. Present when is "identity".
///
[JsonPropertyName("identity")]
public JetstreamIdentity? Identity { get; set; }
///
/// Account event data. Present when is "account".
///
[JsonPropertyName("account")]
public JetstreamAccount? Account { get; set; }
}
///
/// A Jetstream commit event representing a single record operation.
///
public sealed class JetstreamCommit
{
///
/// The repo revision (TID).
///
[JsonPropertyName("rev")]
public string? Rev { get; set; }
///
/// The operation type: "create", "update", or "delete".
///
[JsonPropertyName("operation")]
public string? Operation { get; set; }
///
/// The collection NSID (e.g. "app.bsky.feed.post").
///
[JsonPropertyName("collection")]
public string? Collection { get; set; }
///
/// The record key within the collection.
///
[JsonPropertyName("rkey")]
public string? Rkey { get; set; }
///
/// The full record as a JSON element. Present on "create" and "update", absent on "delete".
///
[JsonPropertyName("record")]
public JsonElement? Record { get; set; }
///
/// The CID of the record. Present on "create" and "update", absent on "delete".
///
[JsonPropertyName("cid")]
public string? Cid { get; set; }
}
///
/// A Jetstream identity event indicating a DID document or handle change.
///
public sealed class JetstreamIdentity
{
///
/// The DID.
///
[JsonPropertyName("did")]
public string? Did { get; set; }
///
/// The current handle.
///
[JsonPropertyName("handle")]
public string? Handle { get; set; }
///
/// The sequence number from the upstream firehose.
///
[JsonPropertyName("seq")]
public long? Seq { get; set; }
///
/// Timestamp from the upstream firehose.
///
[JsonPropertyName("time")]
public string? Time { get; set; }
}
///
/// A Jetstream account event indicating an account status change.
///
public sealed class JetstreamAccount
{
///
/// Whether the account is active.
///
[JsonPropertyName("active")]
public bool Active { get; set; }
///
/// The DID.
///
[JsonPropertyName("did")]
public string? Did { get; set; }
///
/// The sequence number from the upstream firehose.
///
[JsonPropertyName("seq")]
public long? Seq { get; set; }
///
/// Timestamp from the upstream firehose.
///
[JsonPropertyName("time")]
public string? Time { get; set; }
///
/// Account status reason if not active (e.g. "deactivated", "takendown", "suspended", "deleted").
///
[JsonPropertyName("status")]
public string? Status { get; set; }
}