using EDPlayerJournal;
using EDPlayerJournal.BGS;
using System.Linq;
using System.Text;

namespace EliteBGS.LogGenerator;

public class KillBondsFormat : GenericFormat<FactionKillBonds> {
    public override string GenerateSummary(Objective objective) {
        StringBuilder builder = new StringBuilder();

        var bonds = objective
            .EnabledOfType<FactionKillBonds>()
            .GroupBy(x => x.VictimFaction)
            .ToDictionary(x => x.Key, x => x.ToList())
            ;

        if (bonds.Count <= 0) {
            return "";
        }

        builder.Append("Killbonds: ");
        foreach (var entry in bonds) {
            long sum = (long)entry.Value.Sum(x => (decimal)x.TotalSum);
            builder.AppendFormat("{0} against {1}, ",
                    Credits.FormatMillions(sum),
                    entry.Key
                );
        }

        if (builder.Length > 2) {
            // Remove trailing comma
            builder.Remove(builder.Length - 2, 2);
        }

        return builder.ToString();
    }
}
