using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using NodaTime;
namespace DysonNetwork.Shared.Models;
public class SnRealtimeCall : ModelBase
{
    public Guid Id { get; set; } = Guid.NewGuid();
    public Instant? EndedAt { get; set; }
    public Guid SenderId { get; set; }
    public SnChatMember Sender { get; set; } = null!;
    public Guid RoomId { get; set; }
    public SnChatRoom Room { get; set; } = null!;
    /// 
    /// Provider name (e.g., "cloudflare", "agora", "twilio")
    /// 
    public string? ProviderName { get; set; }
    /// 
    /// Service provider's session identifier
    /// 
    public string? SessionId { get; set; }
    /// 
    /// JSONB column containing provider-specific configuration
    /// 
    [Column(name: "upstream", TypeName = "jsonb")]
    public string? UpstreamConfigJson { get; set; }
    /// 
    /// Deserialized upstream configuration
    /// 
    [NotMapped]
    public Dictionary UpstreamConfig
    {
        get => string.IsNullOrEmpty(UpstreamConfigJson)
            ? new Dictionary()
            : JsonSerializer.Deserialize>(UpstreamConfigJson) ?? new Dictionary();
        set => UpstreamConfigJson = value.Count > 0 
            ? JsonSerializer.Serialize(value) 
            : null;
    }
}