namespace FileAccessAgent.Infrastructure.Services;

internal static class ObjectKeyHelper
{
    public static string Normalize(string objectKey)
    {
        if (string.IsNullOrWhiteSpace(objectKey))
        {
            throw new InvalidOperationException("objectKey is required.");
        }

        var normalized = objectKey.Trim().Replace('\\', '/');
        if (normalized.StartsWith('/'))
        {
            normalized = normalized.TrimStart('/');
        }

        if (normalized.Contains("..", StringComparison.Ordinal))
        {
            throw new InvalidOperationException("objectKey cannot contain path traversal.");
        }

        return normalized;
    }
}
