// 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.Tasks; using CommunityToolkit.Diagnostics; using OwlCore.Extensions; using StrixMusic.Sdk.AppModels; using StrixMusic.Sdk.CoreModels; namespace StrixMusic.Sdk.AdapterModels { /// /// Merged multiple into a single /// public class MergedUrl : IUrl, IMergedMutable { private readonly ICoreUrl _preferredSource; private readonly List _sources; /// /// Initializes a new instance of the class. /// public MergedUrl(IReadOnlyList sources) { Guard.IsNotNull(sources, nameof(sources)); _sources = sources.ToList(); _preferredSource = _sources[0]; } /// public event EventHandler? SourcesChanged; /// public string Label => _preferredSource.Label; /// public Uri Url => _preferredSource.Url; /// public UrlType Type => _preferredSource.Type; /// public IReadOnlyList Sources => _sources; /// public void AddSource(ICoreUrl itemToMerge) { Guard.IsNotNull(itemToMerge, nameof(itemToMerge)); _sources.Add(itemToMerge); SourcesChanged?.Invoke(this, EventArgs.Empty); } /// public void RemoveSource(ICoreUrl itemToRemove) { Guard.IsNotNull(itemToRemove, nameof(itemToRemove)); _sources.Remove(itemToRemove); SourcesChanged?.Invoke(this, EventArgs.Empty); } /// public bool Equals(ICoreUrl other) { return other?.Url == Url && other?.Type == Type && other?.Label == Label; } /// public async ValueTask DisposeAsync() { await _sources.InParallel(x => x.DisposeAsync().AsTask()); } } }