classdef InputValidator
%InputValidator Static methods to validate metrics-specific data,
%providing friendly names.

% Copyright 2021 The MathWorks, Inc.
    methods (Static)

        function fcn = metricsString
        % A string that matches Prometheus metrics name pattern
            function matchesPattern(s)
                mustBeNonzeroLengthText(s);
                mustBeTextScalar(s);
                if ~isvarname(s)
                    error(message("MPS:MATLAB:Metrics:IncorrectNameFormat"));
                end
            end
            fcn = @matchesPattern;
        end

        function fcn = metricsNumeric
        % A number that matches Prometheus metrics gauge value definition
            function scalarNumeric(n)
                validateattributes(n, {'numeric'}, {'scalar','nonempty'} );
                mustBeReal(n);
            end
            fcn = @scalarNumeric;
        end

        function fcn = metricsPositive
        % A positive (> 0) number that matches Prometheus metrics counter value
            function scalarPositive(n)
                isNum = prodserver.metrics.internal.InputValidator.metricsNumeric;
                isNum(n);
                mustBePositive(n);
            end
            fcn = @scalarPositive;
        end

    end
end
