﻿using System;
using System.Threading.Tasks;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using NewsWrapper.Interfaces;
using NewsWrapper.types;
using NewsWrapper.Requesters;


namespace NewsWrapper.Controllers
{

    //[RoutePrefix("api/News")]
    public class NewsController : ApiController
    {
        ConfigurationProvider configuration = new ConfigurationProvider();
        [HttpPost]
        public async Task<IHttpActionResult> GetNews([FromBody] string[] sources)
        {

            if (sources.Length != 0 )
            {
               
                RequestFactory factory = new RequestFactory(configuration, sources.ToList());
                var newsAPI = factory.GetApiProviderInstance(Providers.NewsAPI);
                var data = await newsAPI.GetCall<NewsListing>(sources.ToList());
                return Ok(data);
        
            }
            return Ok("No sources specified");
        }
   

    }
}