using System.Diagnostics.CodeAnalysis;
namespace StardewModdingAPI.Web.Framework.LogParsing.Models
{
/// Metadata about a mod or content pack in the log.
public class LogModInfo
{
/*********
** Accessors
*********/
/// The mod name.
public string Name { get; }
/// The mod author.
public string Author { get; }
/// The mod version.
public string Version { get; private set; }
/// The mod description.
public string Description { get; }
/// The update version.
public string? UpdateVersion { get; private set; }
/// The update link.
public string? UpdateLink { get; private set; }
/// The name of the mod for which this is a content pack (if applicable).
public string? ContentPackFor { get; }
/// The number of errors logged by this mod.
public int Errors { get; set; }
/// Whether the mod was loaded into the game.
public bool Loaded { get; }
/// Whether the mod has an update available.
[MemberNotNullWhen(true, nameof(LogModInfo.UpdateVersion), nameof(LogModInfo.UpdateLink))]
public bool HasUpdate => this.UpdateVersion != null && this.Version != this.UpdateVersion;
/// Whether the mod is a content pack for another mod.
[MemberNotNullWhen(true, nameof(LogModInfo.ContentPackFor))]
public bool IsContentPack => !string.IsNullOrWhiteSpace(this.ContentPackFor);
/*********
** Public methods
*********/
/// Construct an instance.
/// The mod name.
/// The mod author.
/// The mod version.
/// The mod description.
/// The update version.
/// The update link.
/// The name of the mod for which this is a content pack (if applicable).
/// The number of errors logged by this mod.
/// Whether the mod was loaded into the game.
public LogModInfo(string name, string author, string version, string description, string? updateVersion = null, string? updateLink = null, string? contentPackFor = null, int errors = 0, bool loaded = true)
{
this.Name = name;
this.Author = author;
this.Version = version;
this.Description = description;
this.UpdateVersion = updateVersion;
this.UpdateLink = updateLink;
this.ContentPackFor = contentPackFor;
this.Errors = errors;
this.Loaded = loaded;
}
/// Add an update alert for this mod.
/// The update version.
/// The update link.
public void SetUpdate(string updateVersion, string updateLink)
{
this.UpdateVersion = updateVersion;
this.UpdateLink = updateLink;
}
/// Override the version number, for cases like SMAPI itself where the version is only known later during parsing.
/// The new mod version.
public void OverrideVersion(string version)
{
this.Version = version;
}
}
}