using System.Text.Json;

public static class BufferedSyncWriter
{
    public static void Enqueue(
        GatewayDbContext db,
        BufferedSyncItemType itemType,
        object payload,
        string idempotencyKey,
        Guid encounterId,
        DateTimeOffset recordedAt)
    {
        db.BufferedSyncItems.Add(new BufferedSyncItem
        {
            Id = Guid.NewGuid(),
            ItemType = itemType,
            Payload = JsonSerializer.Serialize(payload),
            IdempotencyKey = idempotencyKey,
            EncounterId = encounterId,
            RecordedAt = recordedAt,
            CreatedAt = DateTimeOffset.UtcNow
        });
    }
}