using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson.Serialization.Options;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
namespace StardewModdingAPI.Web.Framework.Caching.Wiki
{
/// The model for cached wiki mods.
internal class CachedWikiMod
{
/*********
** Accessors
*********/
/****
** Tracking
****/
/// The internal MongoDB ID.
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "Named per MongoDB conventions.")]
public ObjectId _id { get; set; }
/// When the data was last updated.
public DateTimeOffset LastUpdated { get; set; }
/****
** Mod info
****/
/// The mod's unique ID. If the mod has alternate/old IDs, they're listed in latest to newest order.
public string[] ID { get; set; }
/// The mod's display name. If the mod has multiple names, the first one is the most canonical name.
public string[] Name { get; set; }
/// The mod's author name. If the author has multiple names, the first one is the most canonical name.
public string[] Author { get; set; }
/// The mod ID on Nexus.
public int? NexusID { get; set; }
/// The mod ID in the Chucklefish mod repo.
public int? ChucklefishID { get; set; }
/// The mod ID in the CurseForge mod repo.
public int? CurseForgeID { get; set; }
/// The mod key in the CurseForge mod repo (used in mod page URLs).
public string CurseForgeKey { get; set; }
/// The mod ID in the ModDrop mod repo.
public int? ModDropID { get; set; }
/// The GitHub repository in the form 'owner/repo'.
public string GitHubRepo { get; set; }
/// The URL to a non-GitHub source repo.
public string CustomSourceUrl { get; set; }
/// The custom mod page URL (if applicable).
public string CustomUrl { get; set; }
/// The name of the mod which loads this content pack, if applicable.
public string ContentPackFor { get; set; }
/// The human-readable warnings for players about this mod.
public string[] Warnings { get; set; }
/// The URL of the pull request which submits changes for an unofficial update to the author, if any.
public string PullRequestUrl { get; set; }
/// Special notes intended for developers who maintain unofficial updates or submit pull requests.
public string DevNote { get; set; }
/// The link anchor for the mod entry in the wiki compatibility list.
public string Anchor { get; set; }
/****
** Stable compatibility
****/
/// The compatibility status.
public WikiCompatibilityStatus MainStatus { get; set; }
/// The human-readable summary of the compatibility status or workaround, without HTML formatting.
public string MainSummary { get; set; }
/// The game or SMAPI version which broke this mod (if applicable).
public string MainBrokeIn { get; set; }
/// The version of the latest unofficial update, if applicable.
public string MainUnofficialVersion { get; set; }
/// The URL to the latest unofficial update, if applicable.
public string MainUnofficialUrl { get; set; }
/****
** Beta compatibility
****/
/// The compatibility status.
public WikiCompatibilityStatus? BetaStatus { get; set; }
/// The human-readable summary of the compatibility status or workaround, without HTML formatting.
public string BetaSummary { get; set; }
/// The game or SMAPI version which broke this mod (if applicable).
public string BetaBrokeIn { get; set; }
/// The version of the latest unofficial update, if applicable.
public string BetaUnofficialVersion { get; set; }
/// The URL to the latest unofficial update, if applicable.
public string BetaUnofficialUrl { get; set; }
/****
** Version maps
****/
/// Maps local versions to a semantic version for update checks.
[BsonDictionaryOptions(Representation = DictionaryRepresentation.ArrayOfArrays)]
public IDictionary MapLocalVersions { get; set; }
/// Maps remote versions to a semantic version for update checks.
[BsonDictionaryOptions(Representation = DictionaryRepresentation.ArrayOfArrays)]
public IDictionary MapRemoteVersions { get; set; }
/*********
** Accessors
*********/
/// Construct an instance.
public CachedWikiMod() { }
/// Construct an instance.
/// The mod data.
public CachedWikiMod(WikiModEntry mod)
{
// tracking
this.LastUpdated = DateTimeOffset.UtcNow;
// mod info
this.ID = mod.ID;
this.Name = mod.Name;
this.Author = mod.Author;
this.NexusID = mod.NexusID;
this.ChucklefishID = mod.ChucklefishID;
this.CurseForgeID = mod.CurseForgeID;
this.CurseForgeKey = mod.CurseForgeKey;
this.ModDropID = mod.ModDropID;
this.GitHubRepo = mod.GitHubRepo;
this.CustomSourceUrl = mod.CustomSourceUrl;
this.CustomUrl = mod.CustomUrl;
this.ContentPackFor = mod.ContentPackFor;
this.PullRequestUrl = mod.PullRequestUrl;
this.Warnings = mod.Warnings;
this.DevNote = mod.DevNote;
this.Anchor = mod.Anchor;
// stable compatibility
this.MainStatus = mod.Compatibility.Status;
this.MainSummary = mod.Compatibility.Summary;
this.MainBrokeIn = mod.Compatibility.BrokeIn;
this.MainUnofficialVersion = mod.Compatibility.UnofficialVersion?.ToString();
this.MainUnofficialUrl = mod.Compatibility.UnofficialUrl;
// beta compatibility
this.BetaStatus = mod.BetaCompatibility?.Status;
this.BetaSummary = mod.BetaCompatibility?.Summary;
this.BetaBrokeIn = mod.BetaCompatibility?.BrokeIn;
this.BetaUnofficialVersion = mod.BetaCompatibility?.UnofficialVersion?.ToString();
this.BetaUnofficialUrl = mod.BetaCompatibility?.UnofficialUrl;
// version maps
this.MapLocalVersions = mod.MapLocalVersions;
this.MapRemoteVersions = mod.MapRemoteVersions;
}
/// Reconstruct the original model.
public WikiModEntry GetModel()
{
var mod = new WikiModEntry
{
ID = this.ID,
Name = this.Name,
Author = this.Author,
NexusID = this.NexusID,
ChucklefishID = this.ChucklefishID,
CurseForgeID = this.CurseForgeID,
CurseForgeKey = this.CurseForgeKey,
ModDropID = this.ModDropID,
GitHubRepo = this.GitHubRepo,
CustomSourceUrl = this.CustomSourceUrl,
CustomUrl = this.CustomUrl,
ContentPackFor = this.ContentPackFor,
Warnings = this.Warnings,
PullRequestUrl = this.PullRequestUrl,
DevNote = this.DevNote,
Anchor = this.Anchor,
// stable compatibility
Compatibility = new WikiCompatibilityInfo
{
Status = this.MainStatus,
Summary = this.MainSummary,
BrokeIn = this.MainBrokeIn,
UnofficialVersion = this.MainUnofficialVersion != null ? new SemanticVersion(this.MainUnofficialVersion) : null,
UnofficialUrl = this.MainUnofficialUrl
},
// version maps
MapLocalVersions = this.MapLocalVersions,
MapRemoteVersions = this.MapRemoteVersions
};
// beta compatibility
if (this.BetaStatus != null)
{
mod.BetaCompatibility = new WikiCompatibilityInfo
{
Status = this.BetaStatus.Value,
Summary = this.BetaSummary,
BrokeIn = this.BetaBrokeIn,
UnofficialVersion = this.BetaUnofficialVersion != null ? new SemanticVersion(this.BetaUnofficialVersion) : null,
UnofficialUrl = this.BetaUnofficialUrl
};
}
return mod;
}
}
}