using Newtonsoft.Json;
namespace OrderSupportTicket.Models;
///
/// SSE 实时通知。通知只包含摘要定位信息,收到后需要重新查询对应工单。
///
public sealed class TicketRealtimeNotification
{
///
/// 服务端事件 ID,用于至少一次投递时的去重。
///
////[JsonProperty("eventId")]
public string EventId { get; set; }
///
/// 事件类型,例如 relay.ticket.message_added 或 resync_required。
///
////[JsonProperty("type")]
public string Type { get; set; }
///
/// 发生变更的店铺 APPID。
///
////[JsonProperty("appId")]
public string AppId { get; set; }
///
/// 发生变更的微信订单号,保持为数字字符串。
///
////[JsonProperty("wechatOrderId")]
public string WechatOrderId { get; set; }
///
/// 新增消息的消息 ID。
///
////[JsonProperty("messageId")]
public string MessageId { get; set; }
///
/// 工单版本号,按服务端返回的字符串原样保存。
///
////[JsonProperty("version")]
public string Version { get; set; }
///
/// 事件发生时间,保留服务端 ISO 8601 字符串。
///
////[JsonProperty("occurredAt")]
public string OccurredAt { get; set; }
///
/// 是否要求客户端执行全量重新同步。
///
[JsonIgnore]
public bool IsResyncRequired =>
string.Equals(Type, "resync_required", System.StringComparison.OrdinalIgnoreCase);
}
///
/// SSE 连接状态。
///
public enum TicketRealtimeState
{
///
/// 未连接。
///
Disconnected,
///
/// 正在建立连接。
///
Connecting,
///
/// 已连接并接收事件。
///
Connected,
///
/// 连接中断,正在自动重连。
///
Reconnecting
}
///
/// SSE 通知事件参数。
///
public sealed class TicketRealtimeNotificationEventArgs : System.EventArgs
{
///
/// 创建 SSE 通知事件参数。
///
/// 收到的 SSE 通知。
public TicketRealtimeNotificationEventArgs(TicketRealtimeNotification notification)
{
Notification = notification;
}
///
/// 收到的 SSE 通知。
///
public TicketRealtimeNotification Notification { get; }
}
///
/// SSE 连接状态变化事件参数。
///
public sealed class TicketRealtimeStateChangedEventArgs : System.EventArgs
{
///
/// 创建 SSE 连接状态变化事件参数。
///
/// 变化后的连接状态。
/// 可选的连接状态说明。
public TicketRealtimeStateChangedEventArgs(
TicketRealtimeState state,
string message = null)
{
State = state;
Message = message;
}
///
/// 变化后的连接状态。
///
public TicketRealtimeState State { get; }
///
/// 连接状态说明。
///
public string Message { get; }
}