using System.Collections.Generic;
using EDPlayerJournal.BGS;

namespace EliteBGS;

public class Report {
    public List<Objective> Objectives { get; set; } = new List<Objective>();

    public Report() { }

    public Report(List<Transaction> transactions) {
        Populate(transactions);
    }

    private void Populate(List<Transaction> transactions) {
        if (transactions == null || transactions.Count == 0) {
            return;
        }

        foreach (Transaction t in transactions) {
            Objective o;
            if (t.SystemContribution) {
                o = Objectives.Find(x => x.Matches(t.System));
            } else {
                o = Objectives.Find(x => x.Matches(t.System, t.Faction));
            }

            if (o == null) {
                if (t.SystemContribution) {
                    o = new Objective() { System = t.System };
                } else {
                    o = new Objective() { Faction = t.Faction, System = t.System };
                }
                Objectives.Add(o);
            }

            o.UITransactions.Add(new UITransaction(t));
        }
    }
}
