module.exports = {
    validateDocumentId(documentId, documentIdRules) {
        const alphaNumeric = /^[0-9a-zA-Z-]+$/;
        if (!documentIdRules) {
            documentIdRules = {};
        }

        if (!documentIdRules.minimumLength) {
            documentIdRules.minimumLength = 24; // default to 24, the length of an ObjectId
        }

        const result = {
            valid: true,
            reason: documentId + ' documentId is valid.'
        };

        if (!documentId) {
            result.valid = false;
            result.reason = 'Unable to validate undefined documentId.';
        } else if (typeof documentId !== 'string') {
            result.valid = false;
            result.reason = 'DocumentId should be a string.';
        } else if (!documentId.match(alphaNumeric)) {
            result.valid = false;
            result.reason = 'DocumentId should consist of alphanumeric characters.';
        } else if (documentIdRules.minimumLength > documentId.length) {
            result.valid = false;
            result.reason = 'DocumentId should have a minimum length of ' + documentIdRules.minimumLength + '.';
        }

        return result;
    }
};

