using StabilityMatrix.Core.Models.FileInterfaces;
namespace StabilityMatrix.Core.Models.Packages.Extensions;
public record InstalledPackageExtension
{
///
/// All folders or files of the extension.
///
public required IEnumerable Paths { get; init; }
///
/// Primary path of the extension.
///
public IPathObject? PrimaryPath => Paths.FirstOrDefault();
///
/// The version of the extension.
///
public PackageExtensionVersion? Version { get; init; }
///
/// Remote git repository url, if the extension is a git repository.
///
public string? GitRepositoryUrl { get; init; }
///
/// The PackageExtension definition, if available.
///
public PackageExtension? Definition { get; init; }
public string Title
{
get
{
if (Definition?.Title is { } title)
{
return title;
}
if (Paths.FirstOrDefault()?.Name is { } pathName)
{
return pathName;
}
return "";
}
}
///
/// Path containing PrimaryPath and its parent.
///
public string DisplayPath =>
PrimaryPath switch
{
null => "",
DirectoryPath { Parent: { } parentDir } dir => $"{parentDir.Name}/{dir.Name}",
_ => PrimaryPath.Name
};
}