using EDPlayerJournal.Entries;

namespace EDPlayerJournal.BGS;

public class ThargoidKill : Transaction {
    /// <summary>
    /// Thargoid vessel that was killed
    /// </summary>
    public ThargoidVessel ThargoidType { get; set; } = ThargoidVessel.Unknown;

    /// <summary>
    /// Name of the thargoid type killed
    /// </summary>
    public string? ThargoidName { get; set; }

    /// <summary>
    /// Total reward received
    /// </summary>
    public ulong TotalReward {
        get { return (ulong)Entries.OfType<FactionKillBondEntry>().Sum(x => (decimal)x.Reward); }
    }

    /// <summary>
    /// Kiling thargoids contributes to the system wide effort of
    /// the thargoid war.
    /// </summary>
    public override bool SystemContribution {
        get { return true; }
    }

    public ThargoidKill() { }

    public ThargoidKill(FactionKillBondEntry entry) {
        if (!Factions.IsThargoid(entry.VictimFaction)) {
            throw new Exception("Not a valid thargoid kill");
        }

        Entries.Add(entry);

        ThargoidType = Thargoid.GetVesselByPayout(entry.Reward);
        ThargoidName = Thargoid.GetVesselName(ThargoidType);
    }

    public override string ToString() {
        return string.Format("{0}x {1} killed", Entries.Count, ThargoidName);
    }
}
