using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json; namespace Svrnty.Sample.Data.Entities; /// /// Represents an AI agent conversation with message history /// [Table("conversations", Schema = "agent")] public class Conversation { [Key] [Column("id")] public Guid Id { get; set; } = Guid.NewGuid(); /// /// JSON array of messages in the conversation /// [Column("messages", TypeName = "jsonb")] [Required] public string MessagesJson { get; set; } = "[]"; [Column("created_at")] [Required] public DateTime CreatedAt { get; set; } = DateTime.UtcNow; [Column("updated_at")] [Required] public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; /// /// Convenience property to get/set messages as objects (not mapped to database) /// [NotMapped] public List Messages { get => string.IsNullOrEmpty(MessagesJson) ? new List() : JsonSerializer.Deserialize>(MessagesJson) ?? new List(); set => MessagesJson = JsonSerializer.Serialize(value); } } /// /// Individual message in a conversation /// public class ConversationMessage { public string Role { get; set; } = string.Empty; public string Content { get; set; } = string.Empty; public DateTime Timestamp { get; set; } = DateTime.UtcNow; }