(function () {
    "use strict";

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

    function factory($http, $q) {

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

        var _getByCNPJ = function (cnpj) {
            var deferred = $q.defer();
            var args = { 'cnpj': cnpj }
            $http.post('/terceiro/getbycnpj', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        var _getLookup = function (chaves) {
            var deferred = $q.defer();
            var args = { 'chaves': chaves, skip: 0, take: 15 };
            $http.post('/terceiro/getlookup', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });

            return deferred.promise;
        };

        return {
            get: _get,
            getByCNPJ: _getByCNPJ,
            getLookup: _getLookup
    };
    }

})();