using Microsoft.AspNetCore.Mvc;
using isnd.Services;
using isn.Abstract;
using isn.abst;
using isnd.Interfaces;
using System.Linq;
using isnd.Entities;

namespace isnd.Controllers
{
    /// <summary>
    /// Api Controller
    /// </summary>
    public  class ApiController : Controller
    {
        private readonly IPackageManager packageManager;
        private readonly Resource[] resources;

        /// <summary>
        /// Api Controller Constructor
        /// </summary>
        /// <param name="pm"></param>
        public ApiController(IPackageManager pm)
        {
            packageManager = pm;
            resources = packageManager.GetResources().ToArray();
        }

        /// <summary>
        /// API index
        /// </summary>
        /// <returns></returns>
        [HttpGet("~" + Constants.ApiVersionPrefix + ApiConfig.Index)]
        public IActionResult ApiIndex()
        {
            return Ok(new ApiIndexViewModel(packageManager.CatalogBaseUrl){ Version = PackageManager.BASE_API_LEVEL, Resources = resources });
        }
    }
        
}