(function () {
    'use strict';

    angular
        .module('app')
        .service('UtilService', UtilService);

    UtilService.$inject = ['$http'];

    function UtilService($http) {

        this.mapObject = function (objOrigem, objDestino) {
            for (var i in objOrigem) {
                objOrigem[i] = objDestino[i];
            }
            return objOrigem;
        };

        this.arrayFirst = function (array, predicate, predicateOwner) {
            for (var i = 0, j = array.length; i < j; i++)
                if (predicate.call(predicateOwner, array[i]))
                    return array[i];
            return null;
        };

        this.arrayMap = function (array, mapping) {
            array = array || [];
            var result = [];
            for (var i = 0, j = array.length; i < j; i++)
                result.push(mapping(array[i]));
            return result;
        };

        this.arrayFilter = function (array, predicate) {
            array = array || [];
            var result = [];
            for (var i = 0, j = array.length; i < j; i++)
                if (predicate(array[i]))
                    result.push(array[i]);
            return result;
        };

        this.getMillisecondsFromDate = function (data) {
            
            if (data)
                return ((data.getHours() * 60 + data.getMinutes()) * 1000);

            return 0;
        }
    }
})();