using MangaReader.Core.Search;
using MangaReader.Core.Sources.NatoManga.Api;

namespace MangaReader.Core.Sources.NatoManga.Search;

public partial class NatoMangaSearchProvider(INatoMangaClient natoMangaClient) : IMangaSearchProvider
{
    public string SourceId => "NatoManga";

    public async Task<MangaSearchResult[]> SearchAsync(string keyword, CancellationToken cancellationToken)
    {
        NatoMangaSearchResult[] searchResults = await natoMangaClient.SearchAsync(keyword, cancellationToken);

        List<MangaSearchResult> mangaSearchResults = [];

        foreach (NatoMangaSearchResult searchResult in searchResults)
        {
            MangaSearchResult mangaSearchResult = new()
            {
                Title = searchResult.Name,
                Thumbnail = searchResult.Thumb,
                Url = searchResult.Url
            };

            mangaSearchResults.Add(mangaSearchResult);
        }

        return [.. mangaSearchResults];
    }
}