Files
AlayaCore/AlayaCore/Models/Manifests/ModFileEntry.cs

44 lines
1.3 KiB
C#

using System;
using AlayaCore.Utilities.Enums;
namespace AlayaCore.Models.Manifests
{
[Serializable]
public sealed class ModFileEntry
{
public string FileName { get; }
public FileType Type { get; }
public string? ModrinthId { get; }
public string? ModrinthVersionId { get; }
public string Sha512Hash { get; }
public ModFileEntry(
string name,
FileType type,
string sha512Hash,
string? modrinthId = null,
string? modrinthVersionId = null)
{
FileName = RequireNonEmpty(name, nameof(name));
Type = type;
Sha512Hash = RequireNonEmpty(sha512Hash, nameof(sha512Hash));
ModrinthId = NormalizeOptional(modrinthId);
ModrinthVersionId = NormalizeOptional(modrinthVersionId);
}
private static string RequireNonEmpty(string value, string paramName)
{
if (string.IsNullOrWhiteSpace(value))
{
throw new ArgumentException("Value cannot be null, empty, or whitespace.", paramName);
}
return value;
}
private static string? NormalizeOptional(string? value)
{
return string.IsNullOrWhiteSpace(value) ? null : value;
}
}
}