﻿using System;
using System.Net.Http;

namespace TinyClient
{
    public class Http : IHttp
    {
        private readonly IHttpBuilder _builder;

        public Http(IHttpBuilder builder = null)
        {
            _builder = builder ?? new HttpBuilder(new HttpClient());
        }

        public IHttpBuilder With()
        {
            return _builder;
        }

        public HttpResponse Get(Uri url) => _builder.SendAsync(HttpMethod.Get, url).Result;

        public HttpResponse Get(string url) => _builder.SendAsync(HttpMethod.Get, new Uri(url)).Result;

        public HttpResponse Post(Uri url) => _builder.SendAsync(HttpMethod.Post, url).Result;

        public HttpResponse Post(string url) => _builder.SendAsync(HttpMethod.Post, new Uri(url)).Result;

        public HttpResponse Put(Uri url) => _builder.SendAsync(HttpMethod.Put, url).Result;

        public HttpResponse Put(string url) => _builder.SendAsync(HttpMethod.Put, new Uri(url)).Result;

        public HttpResponse Delete(Uri url) => _builder.SendAsync(HttpMethod.Delete, url).Result;

        public HttpResponse Delete(string url) => _builder.SendAsync(HttpMethod.Delete, new Uri(url)).Result;

        public HttpResponse Options(Uri url) => _builder.SendAsync(HttpMethod.Options, url).Result;

        public HttpResponse Options(string url) => _builder.SendAsync(HttpMethod.Options, new Uri(url)).Result;

        public HttpResponse Head(Uri url) => _builder.SendAsync(HttpMethod.Head, url).Result;

        public HttpResponse Head(string url) => _builder.SendAsync(HttpMethod.Head, new Uri(url)).Result;

        public HttpResponse Trace(Uri url) => _builder.SendAsync(HttpMethod.Trace, url).Result;

        public HttpResponse Trace(string url) => _builder.SendAsync(HttpMethod.Trace, new Uri(url)).Result;

        public HttpResponse Patch(Uri url) => _builder.SendAsync(new HttpMethod("PATCH"), url).Result;

        public HttpResponse Patch(string url) => _builder.SendAsync(new HttpMethod("PATCH"), new Uri(url)).Result;
    }
}
