using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;


namespace AyaNova.Api.Controllers
{
    [ApiController]
    [ApiVersion("8.0")]
    [Route("api/v{version:apiVersion}/notify")]
    [Produces("application/json")]
    [Authorize]
    public class NotifyController : ControllerBase
    {
        private readonly AyContext ct;
        private readonly ILogger<NotifyController> log;
        private readonly ApiServerState serverState;

        /// <summary>
        /// ctor
        /// </summary>
        /// <param name="dbcontext"></param>
        /// <param name="logger"></param>
        /// <param name="apiServerState"></param>  
        public NotifyController(AyContext dbcontext, ILogger<NotifyController> logger, ApiServerState apiServerState)
        {
            ct = dbcontext;
            log = logger;
            serverState = apiServerState;
        }

        /// <summary>
        /// Pre-login route to confirm server is available
        /// </summary>       
        /// <returns></returns>
        [AllowAnonymous]
        [HttpGet("hello")]
        public ActionResult GetPreLoginPing()
        {
            //note: this route is called by the client as the first action so it also acts like a ping to see if the server is up as well
            if (serverState.IsClosed)
                return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
            return Ok(ApiOkResponse.Response(!AyaNova.Core.License.ActiveKey.TrialLicense));
        }



        /// <summary>
        /// Get count of new notifications waiting
        /// </summary>       
        /// <returns></returns>        
        [HttpGet("new-count")]
        public ActionResult GetNewCount()
        {
            //STUB: https://rockfish.ayanova.com/default.htm#!/rfcaseEdit/3783            
            if (serverState.IsClosed)
                return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason));
            return Ok(ApiOkResponse.Response(69));
        }

//TODO: See new count case for gist of it
//todo: see the core-notification.txt spec doc for details and 
//todo: see seemingly countless Notification related cases for details :)

        //------------


    }//eoc
}//eons