#nullable enable namespace bts { using bts.api; using bts.spark; using bts.utils; using System; public readonly struct SyntheticSecurityTuple : IEquatable, IComparable, IComparable { public static readonly Func key_fn = a => a.security.Id; public SyntheticSecurityTuple( SecurityImmutable security, string user_name, ExecutionStrategyImmutable? strategy) { this.security = security; this.user_name = user_name; this.strategy = strategy; } public SecurityImmutable security { get; } public string user_name { get; } public UserTuple user => security.HasSynthetic ? new(security.Synthetic.UserId, user_name) : throw new InvalidOperationException("Security not of type Synthetic"); public ExecutionStrategyImmutable? strategy { get; } public int CompareTo(SyntheticSecurityTuple other) => SecurityComparer.compare(security, other.security); int IComparable.CompareTo(object? obj) => obj is SyntheticSecurityTuple other ? CompareTo(other) : 1; public bool Equals(SyntheticSecurityTuple other) => security == other.security && user_name == other.user_name && EqualityComparer.nullable_equals(strategy, other.strategy); public override bool Equals(object? obj) => EqualityComparer.equals_obj(this, obj); public override int GetHashCode() => security.Id.GetHashCode(); public override string ToString() => user_name == null ? security.ToString()! : $"{user_name}:{security}"; public static bool operator ==(SyntheticSecurityTuple a, SyntheticSecurityTuple b) => a.Equals(b); public static bool operator !=(SyntheticSecurityTuple a, SyntheticSecurityTuple b) => !a.Equals(b); } }