// Copyright (c) Arlo Godfrey. All Rights Reserved.
// Licensed under the GNU Lesser General Public License, Version 3.0 with additional terms.
// See the LICENSE, LICENSE.LESSER and LICENSE.ADDITIONAL files in the project root for more information.
using CommunityToolkit.Diagnostics;
using OwlCore.ComponentModel;
using StrixMusic.Sdk.AppModels;
namespace StrixMusic.Sdk.Plugins.Model
{
///
/// A model plugin is one or more implementations of
/// that modifies the behavior of an interface implementation
/// by wrapping around an existing instance and selectively overriding members.
///
///
/// Contains a chainable plugin builder for every relevant model interface used
/// in the Strix Music SDK.
/// When the chain is built, the first added Plugin is returned, with the next Plugin provided during construction for
/// proxying, which also had the next item passed into it during construction, and so on.
/// When accessing a member, a plugin may retrieve data from the next plugin (or, if none, the actual implementation), and
/// transform or replace it as needed.
/// A plugin may ignore the inner implementation entirely and supply new data.
/// Or, a plugin might not override that member and simply relay data from the actual implementation.
///
public class SdkModelPlugin : IModelPlugin
{
///
/// Initializes a new instance of the class.
///
/// Metadata that identifies this plugin.
public SdkModelPlugin(ModelPluginMetadata metadata)
{
Metadata = metadata;
}
///
public ModelPluginMetadata Metadata { get; }
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder StrixDataRoot { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Downloadable { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Playable { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Album { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Artist { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Playlist { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Track { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Image { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Lyrics { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Url { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder PlayableCollectionGroup { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Library { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder Discoverables { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder RecentlyPlayed { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder SearchHistory { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder SearchResults { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder TrackCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder ArtistCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder AlbumCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder PlaylistCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder ImageCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder UrlCollection { get; } = new();
///
/// All plugins that provide overridden behavior for .
///
public ChainedProxyBuilder GenreCollection { get; } = new();
///
/// Copies all plugins from the provided into this instance.
///
/// The plugin collection to import into this instance.
public void Import(SdkModelPlugin modelPlugin)
{
var currentSdkVersion = typeof(SdkModelPlugin).Assembly.GetName().Version;
if (modelPlugin.Metadata.SdkVersion.Major != currentSdkVersion.Major)
{
ThrowHelper.ThrowArgumentException($"The imported plugin [{modelPlugin.Metadata.Id}] \"{modelPlugin.Metadata.DisplayName}\" was built against SDK " +
$"version {modelPlugin.Metadata.SdkVersion} and is incompatible with the running version {currentSdkVersion}. " +
$"Please ask the author to update the plugin to the latest release of the Strix Music SDK.");
}
StrixDataRoot.AddRange(modelPlugin.StrixDataRoot);
Playable.AddRange(modelPlugin.Playable);
Downloadable.AddRange(modelPlugin.Downloadable);
Album.AddRange(modelPlugin.Album);
Artist.AddRange(modelPlugin.Artist);
Playlist.AddRange(modelPlugin.Playlist);
Track.AddRange(modelPlugin.Track);
Image.AddRange(modelPlugin.Image);
Lyrics.AddRange(modelPlugin.Lyrics);
Url.AddRange(modelPlugin.Url);
PlayableCollectionGroup.AddRange(modelPlugin.PlayableCollectionGroup);
Library.AddRange(modelPlugin.Library);
Discoverables.AddRange(modelPlugin.Discoverables);
RecentlyPlayed.AddRange(modelPlugin.RecentlyPlayed);
SearchHistory.AddRange(modelPlugin.SearchHistory);
SearchResults.AddRange(modelPlugin.SearchResults);
AlbumCollection.AddRange(modelPlugin.AlbumCollection);
ArtistCollection.AddRange(modelPlugin.ArtistCollection);
PlaylistCollection.AddRange(modelPlugin.PlaylistCollection);
TrackCollection.AddRange(modelPlugin.TrackCollection);
ImageCollection.AddRange(modelPlugin.ImageCollection);
UrlCollection.AddRange(modelPlugin.UrlCollection);
GenreCollection.AddRange(modelPlugin.GenreCollection);
}
}
}