var _ = require('lodash');
var assert = {
    hasExtension: function (url) {
        if (!url) {
            throw new Error('url undefined');
        }

        return function (resource) {
            if (!resource) {
                throw new Error('extension undefined');
            }

            if (!resource.extension) {
                return false;
            }

            return resource.extension.reduce(function (prev, extension) {
                if (prev) return prev;

                return extension.url === url;
            }, false);
        }
    },
    hasExtensionEquals: function (match) {
        if (!match) {
            throw new Error('match undefined');
        }

        return function (resource) {
            if (!resource) {
                throw new Error('resource undefined');
            }

            if (!resource.extension) {
                return false;
            }

            return resource.extension.reduce(function (prev, extension) {
                if (prev) return prev;

                var result = _.isEqual(extension, match);
                return result;
            }, false);

        }
    }
};

module.exports = assert;