(function () {
    "use strict";

    angular.module('pos').factory('sugestaoTransferenciaService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (codigo) {
            var deferred = $q.defer();
            var args = { 'codigo': codigo }
            $http.post('/sugestaotransferencia/get', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getAll = function (filtro) {
            var deferred = $q.defer();
            var args = {
                'chaves': filtro.chaves,
                'codigo': filtro.codigo,
                'filialDestino': filtro.filialDestino,
                'emissaoDe': filtro.emissao.de,
                'emissaoAte': filtro.emissao.ate,
                'skip': filtro.skip,
                'take': filtro.take
            }
            $http.post('/sugestaotransferencia/getall', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _count = function (filtro) {
            var deferred = $q.defer();
            var args = {
                'chaves': filtro.chaves,
                'codigo': filtro.codigo,
                'filialDestino': filtro.filialDestino,
                'emissaoDe': filtro.emissao.de,
                'emissaoAte': filtro.emissao.ate
            }
            $http.post('/sugestaotransferencia/count', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getAllPendente = function () {
            var deferred = $q.defer();
            $http.post('/sugestaotransferencia/getallpendente')
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            count: _count,
            getAllPendente: _getAllPendente
        };
    }

})();