// 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.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using StrixMusic.Sdk.AppModels;
using StrixMusic.Sdk.CoreModels;
namespace StrixMusic.Sdk.ViewModels
{
///
/// A ViewModel for .
///
public sealed class SearchViewModel : ObservableObject, ISdkViewModel, ISearch
{
private readonly ISearch _search;
///
/// Creates a new instance of .
///
/// The model to wrap around.
public SearchViewModel(ISearch search)
{
_search = search;
if (search.SearchHistory != null)
SearchHistory = new SearchHistoryViewModel(search.SearchHistory);
}
///
public event EventHandler? SourcesChanged
{
add => _search.SourcesChanged += value;
remove => _search.SourcesChanged -= value;
}
///
public IAsyncEnumerable GetSearchAutoCompleteAsync(string query, CancellationToken cancellationToken = default) => _search.GetSearchAutoCompleteAsync(query, cancellationToken);
///
public bool Equals(ICoreSearch other) => _search.Equals(other);
///
public IReadOnlyList Sources => _search.Sources;
///
public Task GetSearchResultsAsync(string query, CancellationToken cancellationToken = default) => _search.GetSearchResultsAsync(query, cancellationToken);
///
public IAsyncEnumerable GetRecentSearchQueries(CancellationToken cancellationToken = default) => _search.GetRecentSearchQueries(cancellationToken);
///
ISearchHistory? ISearch.SearchHistory => _search.SearchHistory;
///
/// The view model for search history.
///
public SearchHistoryViewModel? SearchHistory { get; }
///
public ValueTask DisposeAsync() => _search.DisposeAsync();
}
}