namespace Backend.Common;

public static class RequestMetadataReader
{
    public static RequestMetadata Read(HttpContext context) =>
        new(ReadClientIp(context), ReadUserAgent(context));

    public static string ReadClientIp(HttpContext context) =>
        context.Connection.RemoteIpAddress?.ToString() ?? "unknown";

    public static string ReadUserAgent(HttpContext context)
    {
        var value = context.Request.Headers.UserAgent.ToString().Trim();
        return value.Length > 400 ? value[..400] : value;
    }
}
