using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

using Monitoring.Common;
using Monitoring.Controllers;

namespace Monitoring.Features.VersionManagement;

[Route("api/version")]
[AllowAnonymous]
public class VersionController : BaseController
{
	public record ResponseModel(string Version);

	[HttpGet(Name = "GetVersion")]
	[ProducesResponseType<ResponseModel>(StatusCodes.Status200OK)]
	public IActionResult GetVersion()
	{
		if (EnvironmentVariables.Has("BUILD_NUMBER"))
		{
			return Ok(new ResponseModel(EnvironmentVariables.Get("BUILD_NUMBER")));
		}

		return Ok(new ResponseModel("1.0.0"));
	}
}