using System.Text;
using EDPlayerJournal.Entries;

namespace EDPlayerJournal.BGS;

public class MissionCompleted : Transaction {
    public MissionCompleted() { }
    public MissionCompleted(MissionCompletedEntry e) {
        Entries.Add(e);
    }

    public string MissionName {
        get {
            MissionCompletedEntry? c = Entries[0] as MissionCompletedEntry;
            if (c == null || c.Mission == null) {
                return "";
            }

            return c.Mission.FriendlyName;
        }
    }

    public string Influence {
        get {
            MissionCompletedEntry? e = (Entries[0] as MissionCompletedEntry);

            if (e == null || Faction == null || e.Mission == null) {
                return "";
            }

            return (e.Mission.GetInfluenceForFaction(Faction, SystemAddress) ?? "");
        }
    }

    public override string ToString() {
        if (Faction == null || Entries.Count <= 0) {
            return "";
        }

        StringBuilder builder = new StringBuilder();
        var entry = Entries[0] as MissionCompletedEntry;

        if (entry == null || entry.Mission == null) {
            return "";
        }

        var influence = entry.Mission.GetInfluenceForFaction(Faction, SystemAddress);

        builder.AppendFormat("{0}", MissionName);
        if (influence != "") {
            builder.AppendFormat(", Influence: {0}", influence);
        }

        return builder.ToString();
    }
}
