summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Framework/IModPage.cs
blob: 85be41e2bef65905bd913f95450d2a2864952e96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using StardewModdingAPI.Toolkit.Framework.UpdateData;

namespace StardewModdingAPI.Web.Framework
{
    /// <summary>Generic metadata about a mod page.</summary>
    internal interface IModPage
    {
        /*********
        ** Accessors
        *********/
        /// <summary>The mod site containing the mod.</summary>
        ModSiteKey Site { get; }

        /// <summary>The mod's unique ID within the site.</summary>
        string Id { get; }

        /// <summary>The mod name.</summary>
        string? Name { get; }

        /// <summary>The mod's semantic version number.</summary>
        string? Version { get; }

        /// <summary>The mod's web URL.</summary>
        string? Url { get; }

        /// <summary>The mod downloads.</summary>
        IModDownload[] Downloads { get; }

        /// <summary>The mod page status.</summary>
        RemoteModStatus Status { get; }

        /// <summary>A user-friendly error which indicates why fetching the mod info failed (if applicable).</summary>
        string? Error { get; }

        /// <summary>Whether the mod data is valid.</summary>
        [MemberNotNullWhen(true, nameof(IModPage.Name), nameof(IModPage.Url))]
        [MemberNotNullWhen(false, nameof(IModPage.Error))]
        bool IsValid { get; }

        /// <summary>Whether this mod page requires update subkeys and does not allow matching downloads without them.</summary>
        bool RequireSubkey { get; }


        /*********
        ** Methods
        *********/
        /// <summary>Get the mod name for an update subkey, if different from the mod page name.</summary>
        /// <param name="subkey">The update subkey.</param>
        string? GetName(string? subkey);

        /// <summary>Get the mod page URL for an update subkey, if different from the mod page it was fetched from.</summary>
        /// <param name="subkey">The update subkey.</param>
        string? GetUrl(string? subkey);

        /// <summary>Set the fetched mod info.</summary>
        /// <param name="name">The mod name.</param>
        /// <param name="version">The mod's semantic version number.</param>
        /// <param name="url">The mod's web URL.</param>
        /// <param name="downloads">The mod downloads.</param>
        IModPage SetInfo(string name, string? version, string url, IEnumerable<IModDownload> downloads);

        /// <summary>Set a mod fetch error.</summary>
        /// <param name="status">The mod availability status on the remote site.</param>
        /// <param name="error">A user-friendly error which indicates why fetching the mod info failed (if applicable).</param>
        IModPage SetError(RemoteModStatus status, string error);
    }
}