using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using OwlCore.AbstractUI.Models; using OwlCore.Events; using OwlCore.Extensions; using StrixMusic.Sdk.MediaPlayback; using StrixMusic.Cores.OwlCoreRpc.Tests.Mock.Items; using StrixMusic.Cores.OwlCoreRpc.Tests.Mock.Library; using StrixMusic.Cores.OwlCoreRpc.Tests.Mock.Search; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.CoreModels; namespace StrixMusic.Cores.OwlCoreRpc.Tests.Mock { internal class MockCore : ICore { private List _devices; private string instanceDescriptor = "For testing only"; private CoreState coreState; public MockCore() { SourceCore = this; InstanceId = Guid.NewGuid().ToString(); Library = new MockCoreLibrary(this); Pins = new MockCorePins(this); RecentlyPlayed = new MockCoreRecentlyPlayed(this); Discoverables = new MockCoreDiscoverables(this); Search = new MockCoreSearch(this); _devices = new List() { new MockCoreDevice(SourceCore), }; } public async Task InitAsync(CancellationToken cancellationToken = default) { await Task.Delay(500); Library.Cast().PopulateMockItems(); CoreState = CoreState.Loaded; } public bool IsInitialized { get; } public event EventHandler? CoreStateChanged; public event CollectionChangedEventHandler? DevicesChanged; /// public event EventHandler? AbstractConfigPanelChanged; public event EventHandler? InstanceDescriptorChanged; public CoreMetadata Registration { get; } = new CoreMetadata(nameof(MockCore), "Mock core", new Uri("https://strixmusic.com/"), Version.Parse("0.0.0.0")); public string InstanceId { get; set; } public string InstanceDescriptor { get => instanceDescriptor; set { instanceDescriptor = value; InstanceDescriptorChanged?.Invoke(this, value); } } /// public AbstractUICollection AbstractConfigPanel { get; } = new("test"); /// public MediaPlayerType PlaybackType { get; } public ICoreUser? User { get; set; } = new MockCoreUser(); public IReadOnlyList Devices => _devices; public ICoreLibrary Library { get; set; } public ICorePlayableCollectionGroup? Pins { get; set; } public ICoreSearch? Search { get; set; } public ICoreRecentlyPlayed? RecentlyPlayed { get; set; } public ICoreDiscoverables? Discoverables { get; set; } public CoreState CoreState { get => coreState; set { coreState = value; CoreStateChanged?.Invoke(this, value); } } public ICore SourceCore { get; set; } public Task GetContextByIdAsync(string id, CancellationToken cancellationToken = default) { return Task.FromResult(id switch { MockContextIds.Album => new MockCoreAlbum(this, id, "Album"), MockContextIds.Artist => new MockCoreArtist(this, id, "Artist"), MockContextIds.Device => new MockCoreDevice(this), MockContextIds.Discoverables => new MockCoreDiscoverables(this), MockContextIds.Image => new MockCoreImage(this, new Uri("https://strixmusic.com/favicon.ico")), MockContextIds.Library => Library, MockContextIds.Pins => Pins, MockContextIds.PlayableCollectionGroup => new MockCorePlayableCollectionGroup(this, id, "Collection group"), MockContextIds.Playlist => new MockCorePlaylist(this, id, "Playlist"), MockContextIds.RecentlyPlayed => RecentlyPlayed, MockContextIds.SearchHistory => Search?.SearchHistory, MockContextIds.SearchResults => new MockCoreSearchResults(this, id), MockContextIds.Track => new MockCoreTrack(this, id, "Track"), _ => throw new NotImplementedException(), }); } public Task GetMediaSourceAsync(ICoreTrack track, CancellationToken cancellationToken = default) { return Task.FromResult(new MockMediaSourceConfig(track.Id, track)); } public void AddMockDevice() { var newDevice = new MockCoreDevice(SourceCore); _devices.Add(newDevice); DevicesChanged?.Invoke(this, new CollectionChangedItem(newDevice, _devices.Count - 1).IntoList(), new List>()); } public void RemoveMockDevice() { var device = _devices[0]; _devices.RemoveAt(0); DevicesChanged?.Invoke(this, new List>(), new CollectionChangedItem(device, 0).IntoList()); } public ValueTask DisposeAsync() { return default; } } }