using MD.PersianDateTime.Standard;

namespace NetinaShop.Api.Controller;

public class HealthController : ICarterModule
{
    public void AddRoutes(IEndpointRouteBuilder app)
    {
        var group = app.NewVersionedApi("Health")
            .MapGroup("health");
        group.MapGet("", GetHealth)
            .WithDisplayName("GetHealth")
            .HasApiVersion(1.0);
    }

    public IResult GetHealth()
    {
        var version = typeof(Program)?.Assembly.GetName()?.Version?.ToString();
        var check = new HealthCheck
        {
            Health = true,
            Version = version ?? string.Empty,
            StartAt = System.Diagnostics.Process.GetCurrentProcess().StartTime.ToString("F"),
            StartAtPersian = new PersianDateTime(System.Diagnostics.Process.GetCurrentProcess().StartTime).ToLongDateTimeString(),
            MachineName = Environment.MachineName
        };
        var process = Process.GetCurrentProcess();
        check.TotalMemory = process.PrivateMemorySize64.ToString();

        return TypedResults.Ok(check);
    }
}