using Microsoft.AspNetCore.Mvc;
using NuGet.Versioning;
using isnd.Entities;
using isn.abst;

namespace isnd.Controllers
{
    public partial class PackagesController
    {
       
        public IActionResult GetVersions(
            string id,
            string lower,
            bool prerelease = false,
            string packageType = null,
            int skip = 0,
            int take = 25)
        {
            if (take > maxTake)
            {
                ModelState.AddModelError("take", "Maximum exceeded");
            }
            // NugetVersion
            if (!NuGetVersion.TryParse(lower, out NuGetVersion parsedVersion))
            {
                ModelState.AddModelError("lower", "invalid version string");
            }
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            return Ok(new
            {
                versions = packageManager.GetVersions(
                    id, parsedVersion, prerelease, packageType, skip, take)
            });
        }
    }
}
