using isnd.Services;
using isnd.Entities;
using Microsoft.AspNetCore.Mvc;
using isn.abst;

namespace isnd.Controllers
{
    public partial class PackagesController
    {
        
        // GET /autocomplete?id=isn.protocol&prerelease=true
        [HttpGet("~" + Constants.ApiVersion + ApiConfig.AutoComplete)]
        public IActionResult AutoComplete(
            string id,
            string semVerLevel,
            bool prerelease = false,
            string packageType = null,
            int skip = 0,
            int take = 25)
        {
            if (take > maxTake)
            {
                ModelState.AddModelError("take", "Maximum exceeded");
            }
            if (semVerLevel != PackageManager.BASE_API_LEVEL)
            {
                ModelState.AddModelError("semVerLevel", PackageManager.BASE_API_LEVEL + " expected");
            }
            if (ModelState.ErrorCount > 0) return BadRequest(ModelState);
        
            return Ok(packageManager.AutoComplete(id,skip,take,prerelease,packageType));
        }
    }
}