using System.Globalization; using System.Text.Json; namespace XFEEDToolBox.Core.Galaxy; /// The original classifier's cached CommanderID equality for a present /// claim. Missing/pending cache data remains null, never a false ownership fact. public sealed record GalaxyNativeColonisationOwnership(ulong LocalCommanderId,ulong ClaimCommanderId,byte ClaimStatus) { public const string Source="original-colonisation-classifier-owner"; public bool Own=>LocalCommanderId==ClaimCommanderId; public static GalaxyNativeColonisationOwnership? FromWire(JsonElement value) { if(value.ValueKind==JsonValueKind.Null)return null; try { ulong Id(string name)=>value.GetProperty(name).ValueKind==JsonValueKind.String&& ulong.TryParse(value.GetProperty(name).GetString(),NumberStyles.None,CultureInfo.InvariantCulture,out var id)&&id is >0 and 3||own.ValueKind is not(JsonValueKind.True or JsonValueKind.False)||own.GetBoolean()!=(local==claim))throw new InvalidDataException("原殖民身份判定不一致。"); return new(local,claim,status); } catch(Exception error)when(error is KeyNotFoundException or InvalidOperationException or FormatException or OverflowException) {throw new InvalidDataException("原殖民身份回执无效。",error);} } } public sealed partial record GalaxyNativeSystemFacts { public GalaxyNativeColonisationOwnership? ColonisationOwnership {get;init;} public bool ColonisationOwnershipRequested {get;init;} }