using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using System.Linq;

namespace EDPlayerJournal.Entries; 
public class SellExplorationDataEntry : Entry {
    public long BaseValue { get; set; }
    public long Bonus { get; set; }

    /// <summary>
    /// Total Earnings are the actual earnings without bonus. So this
    /// value is BaseValue minus any percent a crew pilot takes.
    /// </summary>
    public long TotalEarnings { get; set; }

    public long Total {
        get { return BaseValue + Bonus; }
    }

    public List<string> Systems { get; set; } = new List<string>();
    public List<string> Discovered { get; set; } = new List<string>();

    protected override void Initialise() {
        BaseValue = JSON.Value<long?>("BaseValue") ?? 0;
        Bonus = JSON.Value<long?>("Bonus") ?? 0;
        TotalEarnings = JSON.Value<long?>("TotalEarnings") ?? 0;

        var sys = JSON.Value<JArray>("Systems");
        if (sys != null) {
            Systems = sys.Select(x => x.ToString()).ToList<string>();
        }

        var dis = JSON.Value<JArray>("Discovered");
        if (dis != null) {
            Discovered = dis.Select(x => x.ToString()).ToList<string>();
        }
    }
}
