using System;
using System.Web.Http;

using C4IT.FASD.Base;
using F4SDwebService;

namespace FasdWebService.Controllers
{
    public class CheckConnectionController : ApiController
    {
        public IHttpActionResult Get()
        {
            var SupportAuthorisation = WebApiApplication.Collector?.InfrastructureConfig?.Authorisation != null;

            // the use of ticket completition policy in this request is deprecated, but kept for backwards compatibility
            var completitionPolicy = enumShowDocumentCaseDialog.ifRequired;
            if (WebApiApplication.Collector != null)
            {
                var globalConfig = WebApiApplication.Collector.GetGlobalConfig();
                completitionPolicy = globalConfig.TicketConfiguration.CompletitionPolicy;
            }

            var output = new cFasdApiConnectionInfo() { ServerVersion = cInfo.ProductVersion(), MinCockpitVersion = cInfo.MinClientVersion(), ConfigRevision = 0, SupportAuthorisation = SupportAuthorisation, WebServerStatus = WebApiApplication.Collector?.ServerStatus ?? enumWebServerStatus.starting, showDocumentCaseDialog = completitionPolicy };

            return Ok(output);
        }
    }
}