using EliteBGS.LogGenerator;
using System.Linq;
using System.Text;

namespace EliteBGS;

public class OneLineDiscordLog : DiscordLogGenerator {
    protected override string GenerateObjectiveHeader(Objective objective) {
        if (!string.IsNullOrEmpty(objective.Faction)) {
            return string.Format("**{0}** for **{1}**: ", objective.System, objective.Faction);
        } else {
            return string.Format("**{0}**: ", objective.System);
        }
    }

    protected override string GenerateObjectiveFooter(Objective objective) {
        return "\n";
    }

    protected override string GenerateFooter() {
        return "";
    }

    protected override string GenerateHeader() {
        return "";
    }

    public override string GenerateDiscordLog(Report report) {
        StringBuilder log = new StringBuilder();

        if (report == null) {
            return "";
        }

        var objectives = report.Objectives
            .Where(x => x.IsEnabled && x.Transactions.Count() > 0)
            ;

        if (objectives == null || objectives.Count() <= 0) {
            return "";
        }

        foreach (Objective objective in objectives) {
            log.AppendFormat("{0}", GenerateObjectiveHeader(objective));

            foreach (LogFormatter formatter in formatters) {
                string text = formatter.GenerateSummary(objective);
                text = text.Trim();
                if (!string.IsNullOrEmpty(text)) {
                    log.AppendFormat("{0}; ", text);
                }
            }

            log.AppendFormat("{0}", GenerateObjectiveFooter(objective));
        }

        log.AppendFormat("{0}", GenerateFooter());

        return log.ToString().Trim();
    }

    public override string ToString() {
        return "One Line Report";
    }
}
