using System;
using System.Collections.Generic;
using System.Net.Http;
using Knot.Modules.Stories.Application.Abstractions;
using System.Threading;
using System.Threading.Tasks;

namespace Knot.Modules.Stories.Infrastructure.External;

public sealed class KlipyClient : IKlipyClient
{
    private readonly HttpClient _httpClient;

    public KlipyClient(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }

    public async Task<bool> TestConnectionAsync(string apiKey, CancellationToken ct = default)
    {
        try
        {
            var request = new HttpRequestMessage(HttpMethod.Get, "https://api.klipy.co/v1/trending?limit=1");
            request.Headers.Add("X-API-KEY", apiKey);
            
            using var response = await _httpClient.SendAsync(request, ct);
            return response.IsSuccessStatusCode;
        }
        catch
        {
            return false;
        }
    }

    public async Task<List<string>> SearchVideosAsync(string apiKey, string query, int limit, CancellationToken ct = default)
    {
        // В реальном проекте: десериализация ответа от Klipy API
        return new List<string>();
    }
}
