using Forwarder.Models;

namespace Forwarder.Services.Implementations;

/// <inheritdoc />
public class GeoRitmClient(
	IHttpClientFactory httpClientFactory
) : IGeoRitmClient
{
	public async Task<Result<GetObjectListResponse[]>> GetObjectList(CancellationToken cancellationToken)
	{
		try
		{
			var client = httpClientFactory.CreateClient(HttpClients.GeoRitm);
			var response = await client.PostAsJsonAsync(
				"/restapi/objects/obj-search/",
				new object(),
				cancellationToken);
			_ = response.EnsureSuccessStatusCode();
			var result = await response.Content.ReadFromJsonAsync<GetObjectListResponse[]>(cancellationToken);
			return Result<GetObjectListResponse[]>.Success(result!);
		}
		catch (Exception ex)
		{
			return Result<GetObjectListResponse[]>.Fail(ex.Message);
		}
	}
}
