namespace Salmon.Core; public class Event { public const string TYPE_STATE_CHANGED = "state_changed"; public string UniqueId { get; set; } public string ThrowerId { get; set; } public string Type { get; set; } public DateTime When { get; set; } = DateTime.Now; public Dictionary Properties { get; protected set; } = new Dictionary(); public object? this[string key] { get { if(Properties.ContainsKey(key)) return Properties[key]; return null; } set { if (!Properties.TryAdd(key, value)) Properties[key] = value; } } protected Event() { } public Event(string uniqueId, string throwerId, string type, DateTime? when = null) { UniqueId = uniqueId; ThrowerId = throwerId; Type = type; if(when != null) When = when.Value; } public static Event FromStateChange(string key, object? value, DateTime when) { string id = Guid.NewGuid().ToString(); var ret = new Event(id, key, TYPE_STATE_CHANGED, when); ret[nameof(Triplet.value)] = value; return ret; } }