using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;
namespace StardewModdingAPI.Web.Framework
{
/// Generic metadata about a mod.
internal class ModInfoModel
{
/*********
** Accessors
*********/
/// The mod name.
public string? Name { get; private set; }
/// The mod's web URL.
public string? Url { get; private set; }
/// The mod's latest version.
public ISemanticVersion? Version { get; private set; }
/// The mod's latest optional or prerelease version, if newer than .
public ISemanticVersion? PreviewVersion { get; private set; }
/// The mod availability status on the remote site.
public RemoteModStatus Status { get; private set; }
/// The error message indicating why the mod is invalid (if applicable).
public string? Error { get; private set; }
/// The mod page URL from which can be downloaded, if different from the .
public string? MainModPageUrl { get; private set; }
/// The mod page URL from which can be downloaded, if different from the .
public string? PreviewModPageUrl { get; private set; }
/*********
** Public methods
*********/
/// Construct an empty instance.
public ModInfoModel() { }
/// Construct an instance.
/// The mod name.
/// The mod's web URL.
/// The semantic version for the mod's latest release.
/// The semantic version for the mod's latest preview release, if available and different from .
/// The mod availability status on the remote site.
/// The error message indicating why the mod is invalid (if applicable).
[JsonConstructor]
public ModInfoModel(string name, string url, ISemanticVersion? version, ISemanticVersion? previewVersion = null, RemoteModStatus status = RemoteModStatus.Ok, string? error = null)
{
this
.SetBasicInfo(name, url)
.SetMainVersion(version!)
.SetPreviewVersion(previewVersion)
.SetError(status, error!);
}
/// Set the basic mod info.
/// The mod name.
/// The mod's web URL.
[MemberNotNull(nameof(ModInfoModel.Name), nameof(ModInfoModel.Url))]
public ModInfoModel SetBasicInfo(string name, string url)
{
this.Name = name;
this.Url = url;
return this;
}
/// Set the mod's main version info.
/// The semantic version for the mod's latest stable release.
/// The mod page URL from which can be downloaded, if different from the .
[MemberNotNull(nameof(ModInfoModel.Version))]
public ModInfoModel SetMainVersion(ISemanticVersion version, string? modPageUrl = null)
{
this.Version = version;
this.MainModPageUrl = modPageUrl;
return this;
}
/// Set the mod's preview version info.
/// The semantic version for the mod's latest preview release.
/// The mod page URL from which can be downloaded, if different from the .
public ModInfoModel SetPreviewVersion(ISemanticVersion? version, string? modPageUrl = null)
{
this.PreviewVersion = version;
this.PreviewModPageUrl = modPageUrl;
return this;
}
/// Set a mod error.
/// The mod availability status on the remote site.
/// The error message indicating why the mod is invalid (if applicable).
public ModInfoModel SetError(RemoteModStatus status, string error)
{
this.Status = status;
this.Error = error;
return this;
}
}
}