using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Valg.EVA.Skanning.Scan.Startup.StateReporting
{
    public class HttpReportSink : IReportSink
    {
        protected readonly string EndpointAddress;

        public HttpReportSink(string endpointAddress)
        {
            EndpointAddress = endpointAddress;
        }
        public void Send(StateReport report)
        {
            var task = SendAsync(report);
            
        }

        protected virtual async Task SendAsync(StateReport report)
        {
            var values = new Dictionary<string, string>
            {
                { "report", JsonConvert.SerializeObject(report) }
            };
            var client = new HttpClient();
            var content = new FormUrlEncodedContent(values);
            var response = client.PostAsync(EndpointAddress, content);
            var responseString = await response.Result.Content.ReadAsStringAsync();

        }

    }
}

