using System.Reflection;
using Interfaces;
using Nancy;

namespace RaceLapTimer.ApiControllers
{
    public class SystemApiModule : NancyModule
    {
        private readonly ITransponderUtilityManager _transponderManager;

        public SystemApiModule(ITransponderUtilityManager transponderManager) 
            : base("/api/system")
        {
            _transponderManager = transponderManager;

            Get["info"] = args => GetSystemInfo();
            Get["lasttoken"] = args => GetLastToken();
        }

        private dynamic GetSystemInfo()
        {
            return Response.AsJson(
                new SystemInfo
                {
                    Version = Assembly.GetEntryAssembly().GetName().Version.ToString()
                });
        }

        private dynamic GetLastToken()
        {
            return Response.AsJson(new { Id=_transponderManager.GetLastScannedId()});
        }
    }

    public class SystemInfo
    {
        public string Version { get; set; }
    }
}
