// 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 System;
using System.Collections.Generic;
using StrixMusic.Sdk.BaseModels;
using StrixMusic.Sdk.CoreModels;
namespace StrixMusic.Sdk.Extensions
{
///
/// Extension methods for generic operations on core members.
///
public static partial class Cores
{
///
/// Gets items from a specific collection type in an object that derives multiple collection types.
///
/// The type of the collection we're handling.
/// The type of the returned items.
/// The source collection.
/// The max number of items to return.
/// Get items starting at this index.
/// An of the requested items.
public static IAsyncEnumerable GetItems(this ICoreCollection source, int limit, int offset)
where TCollection : ICoreMember, ICollectionBase
{
if (source == null)
throw new ArgumentNullException(nameof(source));
if (typeof(TCollection) == typeof(ICorePlayableCollectionGroup))
return (IAsyncEnumerable)((ICorePlayableCollectionGroup)source).GetChildrenAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreAlbumCollection))
return (IAsyncEnumerable)((ICoreAlbumCollection)source).GetAlbumItemsAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreArtistCollection))
return (IAsyncEnumerable)((ICoreArtistCollection)source).GetArtistItemsAsync(limit, offset);
if (typeof(TCollection) == typeof(ICorePlaylistCollection))
return (IAsyncEnumerable)((ICorePlaylistCollection)source).GetPlaylistItemsAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreTrackCollection))
return (IAsyncEnumerable)((ICoreTrackCollection)source).GetTracksAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreImageCollection))
return (IAsyncEnumerable)((ICoreImageCollection)source).GetImagesAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreGenreCollection))
return (IAsyncEnumerable)((ICoreGenreCollection)source).GetGenresAsync(limit, offset);
if (typeof(TCollection) == typeof(ICoreUrlCollection))
return (IAsyncEnumerable)((ICoreUrlCollection)source).GetUrlsAsync(limit, offset);
throw new NotSupportedException("Collection type not handled");
}
}
}