using JSMR.Application.Circles.Queries.Search;
using JSMR.Application.Creators.Queries.Search;
using JSMR.Application.Tags.Queries.Search;
using JSMR.Application.VoiceWorks.Queries.Search;
using System.Net.Http.Json;

namespace JSMR.UI.Blazor.Services;

public class VoiceWorksClient(HttpClient http)
{
    public async Task<SearchVoiceWorksResponse?> SearchAsync(SearchVoiceWorksRequest request, CancellationToken ct = default)
    {
        using var resp = await http.PostAsJsonAsync("/api/voiceworks/search", request, ct);
        return await resp.Content.ReadFromJsonAsync<SearchVoiceWorksResponse>(cancellationToken: ct);
    }

    public async Task<SearchCirclesResponse?> SearchAsync(SearchCirclesRequest request, CancellationToken ct = default)
    {
        using var resp = await http.PostAsJsonAsync("/api/circles/search", request, ct);
        return await resp.Content.ReadFromJsonAsync<SearchCirclesResponse>(cancellationToken: ct);
    }

    public async Task<SearchCreatorsResponse?> SearchAsync(SearchCreatorsRequest request, CancellationToken ct = default)
    {
        using var resp = await http.PostAsJsonAsync("/api/creators/search", request, ct);
        return await resp.Content.ReadFromJsonAsync<SearchCreatorsResponse>(cancellationToken: ct);
    }

    public async Task<SearchTagsResponse?> SearchAsync(SearchTagsRequest request, CancellationToken ct = default)
    {
        using var resp = await http.PostAsJsonAsync("/api/tags/search", request, ct);
        return await resp.Content.ReadFromJsonAsync<SearchTagsResponse>(cancellationToken: ct);
    }
}