namespace XFEEliteDangerous.Core;
///
/// Read services for the explicitly fresh local profile subset. This model has
/// no imported reputation, vouchers, engineer progression or trading history.
/// It does not project a captured nonempty commander into empty collections.
///
internal static class NativeCommanderServices
{
private static readonly string[] ranks=["combat","trade","explore","crime","service","empire","federation","power","cqc","soldier","exobiologist","builder","learner"];
internal static NativeDataReply? Handle(AccountState account,string method,string path,IReadOnlyDictionary fields,byte[] body)
{
if(path is not("/2.0/elite/commander/reputation" or "/2.0/elite/voucher/list"
or "/2.0/elite/crafting/engineer/progression" or "/2.0/elite/commander/tradesystems" or "/2.0/elite/inbox" or "/2.0/elite/user/arcs/redeem"
or "/2.0/elite/codex/discovery/summary" or "/2.0/elite/crafting/engineer/pin" or "/2.0/elite/crafting/specials"
or "/2.0/elite/fss/signals" or "/2.0/elite/starsystem/factionconflicts"))return null;
NativeProfileData.VerifyCommander(account,fields);NativeProfileData.Empty(body);
var save=account.NativeSave??throw new NativeDataException(409,"A complete fresh local commander is required.");
if(path=="/2.0/elite/user/arcs/redeem")
{
NativeProfileData.Method(method,"PUT");
// This local ledger has no automatic reward rules configured.
// Redeeming its zero pending earnings cannot grant official value.
return NativeDataReply.Json(new{balance=new{total_balance=account.NativeArx.TotalBalance,current_week_earnings=0,
earned_delta=0,earned_delta_combat=0,earned_delta_trade=0,earned_delta_exploration=0,earned_delta_other=0,week_cap=400}});
}
NativeProfileData.Method(method,"GET");
if(path is "/2.0/elite/fss/signals" or "/2.0/elite/starsystem/factionconflicts")
foreach(var name in new[]{"systemAddr","systemAddress"})
if(fields.TryGetValue(name,out var address)&&(!ulong.TryParse(address,System.Globalization.NumberStyles.None,System.Globalization.CultureInfo.InvariantCulture,out var parsed)
||parsed!=save.Profile.CurrentSystem))throw new NativeDataException(404,"This system is outside the selected local world.");
return path switch
{
//11343C0 accepts an empty regions array and leaves the actual fresh
//local discovery collection empty. Never copy an online commander's
//discovered totals into this account.
"/2.0/elite/codex/discovery/summary"=>NativeDataReply.Json(new{regions=Array.Empty