// 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 System.Linq;
using System.Threading;
using System.Threading.Tasks;
using OwlCore.Events;
using OwlCore.Extensions;
using StrixMusic.Sdk.AdapterModels;
using StrixMusic.Sdk.CoreModels;
using StrixMusic.Sdk.MediaPlayback;
namespace StrixMusic.Sdk.AppModels
{
///
/// Used to create a new playlist that can be added to the backend.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Must use instances to satisfy interface.")]
public sealed class InitialPlaylistData : IPlaylist, IInitialData
{
private readonly IReadOnlyList _sources = new List();
///
/// Holds any tracks that the user wants to add to the playlist on creation.
///
public List Tracks { get; set; } = new();
///
/// Holds any images that the user wants to add to the playlist on creation. These should point to a file that the app has access to.
///
public List Images { get; set; } = new();
///
/// Holds any urls that the user wants to add to the playlist on creation.
///
public List Urls { get; set; } = new();
///
public List? TargetSourceCores { get; set; } = new();
///
public event CollectionChangedEventHandler? ImagesChanged;
///
public event EventHandler? ImagesCountChanged;
///
public event CollectionChangedEventHandler? TracksChanged;
///
public event EventHandler? TracksCountChanged;
///
public event EventHandler? NameChanged;
///
public event EventHandler? DescriptionChanged;
///
public event EventHandler? PlaybackStateChanged;
///
public event EventHandler? DurationChanged;
///
public event EventHandler? LastPlayedChanged;
///
public event EventHandler? IsPlayTrackCollectionAsyncAvailableChanged;
///
public event EventHandler? IsPauseTrackCollectionAsyncAvailableChanged;
///
public event EventHandler? IsChangeNameAsyncAvailableChanged;
///
public event EventHandler? IsChangeDescriptionAsyncAvailableChanged;
///
public event EventHandler? IsChangeDurationAsyncAvailableChanged;
///
public event CollectionChangedEventHandler? UrlsChanged;
///
public event EventHandler? UrlsCountChanged;
///
public event EventHandler? DownloadInfoChanged;
///
public event EventHandler? SourcesChanged;
///
public int TotalImageCount => Images.Count;
///
public int TotalTrackCount => Tracks.Count;
///
public int TotalUrlCount => Urls.Count;
///
public string Id { get; set; } = string.Empty;
///
public string Name { get; set; } = string.Empty;
///
public string? Description { get; set; }
///
public DateTime? LastPlayed { get; }
///
public DownloadInfo DownloadInfo => default;
///
public PlaybackState PlaybackState { get; }
///
public TimeSpan Duration { get; }
///
public DateTime? AddedAt { get; }
///
public IUserProfile? Owner { get; set; }
///
public IPlayableCollectionGroup? RelatedItems { get; }
///
public bool IsPlayTrackCollectionAsyncAvailable { get; }
///
public bool IsPauseTrackCollectionAsyncAvailable { get; }
///
public bool IsChangeNameAsyncAvailable { get; }
///
public bool IsChangeDescriptionAsyncAvailable { get; }
///
public bool IsChangeDurationAsyncAvailable { get; }
///
public Task IsRemoveTrackAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(false);
}
///
public Task IsAddTrackAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(false);
}
///
public Task IsAddImageAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
///
public Task IsRemoveImageAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
///
public Task IsAddUrlAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
///
public Task IsRemoveUrlAvailableAsync(int index, CancellationToken cancellationToken = default)
{
return Task.FromResult(true);
}
///
public Task PlayTrackCollectionAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(false);
}
///
public Task PauseTrackCollectionAsync(CancellationToken cancellationToken = default)
{
return Task.FromResult(false);
}
///
public Task ChangeNameAsync(string name, CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}
///
public Task ChangeDescriptionAsync(string? description, CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}
///
public Task ChangeDurationAsync(TimeSpan duration, CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}
///
public Task StartDownloadOperationAsync(DownloadOperation operation, CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}
///
public Task AddTrackAsync(ITrack track, int index, CancellationToken cancellationToken = default)
{
Tracks.InsertOrAdd(index, track);
return Task.CompletedTask;
}
///
public Task RemoveTrackAsync(int index, CancellationToken cancellationToken = default)
{
Tracks.RemoveAt(index);
return Task.CompletedTask;
}
///
public Task AddImageAsync(IImage image, int index, CancellationToken cancellationToken = default)
{
Images.InsertOrAdd(index, image);
return Task.CompletedTask;
}
///
public Task RemoveImageAsync(int index, CancellationToken cancellationToken = default)
{
Images.RemoveAt(index);
return Task.CompletedTask;
}
///
public Task AddUrlAsync(IUrl url, int index, CancellationToken cancellationToken = default)
{
Urls.InsertOrAdd(index, url);
return Task.CompletedTask;
}
///
public Task RemoveUrlAsync(int index, CancellationToken cancellationToken = default)
{
Urls.RemoveAt(index);
return Task.CompletedTask;
}
///
IReadOnlyList IMerged.Sources => _sources;
///
IReadOnlyList IMerged.Sources => _sources;
///
IReadOnlyList IMerged.Sources => _sources;
///
IReadOnlyList IMerged.Sources => _sources;
///
public IReadOnlyList Sources => _sources;
///
public IAsyncEnumerable GetImagesAsync(int limit, int offset, CancellationToken cancellationToken = default) => Images.Skip(offset).Take(limit).ToAsyncEnumerable();
///
public IAsyncEnumerable GetUrlsAsync(int limit, int offset, CancellationToken cancellationToken = default) => Urls.Skip(offset).Take(limit).ToAsyncEnumerable();
///
public Task PlayTrackCollectionAsync(ITrack track, CancellationToken cancellationToken = default)
{
throw new NotSupportedException();
}
///
public IAsyncEnumerable GetTracksAsync(int limit, int offset, CancellationToken cancellationToken = default) => Tracks.Skip(offset).Take(limit).ToAsyncEnumerable();
///
public bool Equals(ICoreImageCollection other) => false;
///
public bool Equals(ICoreTrackCollection other) => false;
///
public bool Equals(ICoreUrlCollection other) => false;
///
public bool Equals(ICorePlaylistCollectionItem other) => false;
///
public bool Equals(ICorePlaylist other) => false;
///
public ValueTask DisposeAsync() => default;
}
}