using System.Globalization;
using System.Text.Json;
namespace XFEEDToolBox.Core.Galaxy;
/// <summary>The original classifier's cached CommanderID equality for a present
/// claim. Missing/pending cache data remains null, never a false ownership fact.</summary>
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 <ulong.MaxValue
?id:throw new InvalidDataException("原殖民CommanderID资料无效。");
if(value.ValueKind!=JsonValueKind.Object||value.GetProperty("source").GetString()!=Source)throw new InvalidDataException("原殖民身份来源无效。");
var local=Id("localCommanderId");var claim=Id("claimCommanderId");var status=value.GetProperty("claimStatus").GetByte();var own=value.GetProperty("own");
if(status>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;}
}
using System.Globalization;
using System.Text.Json;
namespace XFEEDToolBox.Core.Galaxy;
/// <summary>The original classifier's cached CommanderID equality for a present
/// claim. Missing/pending cache data remains null, never a false ownership fact.</summary>
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 <ulong.MaxValue
?id:throw new InvalidDataException("原殖民CommanderID资料无效。");
if(value.ValueKind!=JsonValueKind.Object||value.GetProperty("source").GetString()!=Source)throw new InvalidDataException("原殖民身份来源无效。");
var local=Id("localCommanderId");var claim=Id("claimCommanderId");var status=value.GetProperty("claimStatus").GetByte();var own=value.GetProperty("own");
if(status>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;}
}