﻿using System;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Aquarium.Api.Requests;

namespace Aquarium.Api.Http
{
    public static class HttpRequest
    {
        private static readonly HttpClient HttpClient = new HttpClient();

        public static async Task<HttpResponseMessage> RequestAsync(ApiRequest apiRequest)
        {
            if (apiRequest == null) throw new ArgumentNullException(nameof(apiRequest));
            var client = HttpClient;
            var request = new HttpRequestMessage(apiRequest.Method, apiRequest.EndPoint)
            {
                Content = apiRequest.Parameters == string.Empty ? null : new StringContent(apiRequest.Parameters, Encoding.UTF8,
                    "application/json")
            };
            return await client.SendAsync(request);
        }
    }
}