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


namespace AyaNova.Api.Controllers
{

    /// <summary>
    /// Enum pick list controller
    /// </summary>
    [ApiController]
    [ApiVersion("8.0")]
    [Route("api/v{version:apiVersion}/[controller]")]
    [Produces("application/json")]
    [Authorize]
    public class TagListController : ControllerBase
    {
        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 TagListController(AyContext dbcontext, ILogger<AyaTypeController> logger, ApiServerState apiServerState)
        {
            ct = dbcontext;
            log = logger;
            serverState = apiServerState;
        }


        /// <summary>
        /// Get tag picklist
        /// 
        /// Required roles: Any
        /// </summary>
        /// <param name="query">The query to filter the returned list by</param>
        /// <returns>Filtered list (maximum 25 items are returned for any query)</returns>
        [HttpGet("picklist")]
        public ActionResult GetPickList([FromQuery]string query)
        {
            if (!serverState.IsOpen)
            {
                return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
            }

            return Ok(ApiOkResponse.Response(TagUtil.PickListFiltered(ct, query),true));
        }



        /// <summary>
        /// Get tag cloud list
        /// 
        /// Required roles: Any
        /// </summary>
        /// <param name="query">The query to filter the returned list by</param>
        /// <returns>List</returns>
        [HttpGet("cloudlist")]
        public ActionResult GetCloudList([FromQuery]string query)
        {
            if (!serverState.IsOpen)
            {
                return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
            }

            return Ok(ApiOkResponse.Response(TagUtil.CloudListFiltered(ct, query), true));
        }



        // /// <summary>
        // /// Get all possible enumerated values picklist key names
        // /// 
        // /// Required roles: Any
        // /// </summary>     
        // /// <returns>List of AyaNova enumerated type list key names that can be fetched from the AyaEnumPickList/GetPickListRoute</returns>
        // [HttpGet("listkeys")]
        // public ActionResult GetTypesList()
        // {
        //     if (!serverState.IsOpen)
        //     {
        //         return StatusCode(503, new ApiErrorResponse(ApiErrorCode.API_CLOSED, null, serverState.Reason));
        //     }

        //     List<KeyValuePair<string, string>> ret = new List<KeyValuePair<string, string>>();            
        //     ret.Add(new KeyValuePair<string, string>("usertypes", "AyaNova user account types"));
        //     ret.Add(new KeyValuePair<string, string>("authorizationroles", "AyaNova user account role types"));
        //     ret.Add(new KeyValuePair<string, string>("AyaType", "All AyaNova object types, use the AyaTypeController route to fetch these"));

        //     return Ok(ApiOkResponse.Response(ret));
        // }




    }//eoc
}//ens