using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;
using AyaNova.Models;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;


namespace AyaNova.Api.Controllers
{

    /// <summary>
    /// AyaType list controller
    /// </summary>
    [ApiVersion("8.0")]
    [Route("api/v{version:apiVersion}/[controller]")]
    [Produces("application/json")]
    public class AyaTypeController : Controller
    {
        private readonly AyContext ct;
        private readonly ILogger<AyaTypeController> log;
        private readonly ApiServerState serverState;


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


        /// <summary>
        /// Get name value list of AyaNova business object types
        /// 
        /// Required roles: Any
        /// </summary>
        /// <returns>List</returns>
        [HttpGet]
        public ActionResult GetAyaTypes()
        {
            if (!serverState.IsOpen)
            {
                return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
            }

            List<NameIdItem> l = new List<NameIdItem>();
            var values = Enum.GetValues(typeof(AyaType));
            foreach (AyaType t in values)
            {

                string name = t.ToString();
                if (t.HasAttribute(typeof(AttachableAttribute)))
                {
                    name += " [Attachable]";
                }


                l.Add(new NameIdItem() { Name = name, Id = (long)t });
            }


            return Ok(new ApiOkResponse(l));
        }







    }
}