using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;

namespace MOH_CRA_XCRMS_Service.Common
{
    public static class CallApi
    {
        /// <summary>
        /// Calls service api using request xml string
        /// </summary>
        /// <param name="requestXml">request xml string</param>
        /// <returns></returns>
        internal static string GetResponse(string requestXml)
        {
            var apiUrl = ConfigurationSettings.AppSettings["ApiUrl"];

            if (requestXml.IsGovTalkMessage())
                if (requestXml.IsPollMessage())
                    apiUrl += "poll";
                else
                    apiUrl += "submission";

            using (var wc = new WebClient())
            {
                wc.Headers[HttpRequestHeader.ContentType] = "application/xml";
                wc.Encoding = Encoding.UTF8;

                return wc.UploadString(apiUrl, requestXml);
            }
        }
    }
}