/* global angular, api_url */

angular.module("app").service("TagsService", [
    '$uhttp',
    function ($uhttp) {
        var controller = "tags/";

        // ----- GET -----
        this.getAllTags = function (by_page, params) {
            return $uhttp({
                url: api_url + controller + 'get_all_tags' + '/by_page/' + by_page + params
            });
        };
        
        // Método para obtener TAGs por categoría de saldo sin paginación
        this.getTagsBySaldo = function (categoria, status) {
            return $uhttp({
                url: api_url + controller + 'get_tags_by_saldo',
                method: "GET",
                params: {
                    categoria: categoria,
                    status: status || 1
                }
            });
        };
        
        // Nuevo método para obtener TAGs por estado de asignación sin paginación
        this.getTagsByAsignacion = function (categoria, status) {
            return $uhttp({
                url: api_url + controller + 'get_tags_by_asignacion',
                method: "GET",
                params: {
                    categoria: categoria,
                    status: status || 1
                }
            });
        };
        
        this.getTagById = function (tag_id) {
            return $uhttp({
                url: api_url + controller + 'get_tag_by_id',
                method: "GET",
                params: {
                    id: tag_id
                }
            });
        };

        this.buscarNumeroEconomico = function (filtros) {
            return $uhttp({
                url: api_url + controller + 'buscar_numero_economico',
                method: "GET",
                params: filtros
            });
        };
        
        this.getLastRechargeMovement = function (tag_id) {
            return $uhttp({
                url: api_url + controller + 'get_last_recharge_movement',
                method: "GET",
                params: {
                    id: tag_id
                }
            });
        };
        
        // ----- POST -----
        this.create = function (data) {
            return $uhttp({
                url: api_url + controller + 'create',
                method: "POST",
                data: data
            });
        };

        this.assignTag = function (tag_id, data) {
            return $uhttp({
                url: api_url + controller + 'assign_tag',
                method: "POST",
                data: data,
                params: {
                    id: tag_id
                }
            });
        };

        this.unassignTag = function (tag_id, data) {
            return $uhttp({
                url: api_url + controller + 'unassign_tag',
                method: "POST",
                data: data,
                params: {id: tag_id}
            });
        };
        
        this.rechargeTag = function (tag_id, data) {
            return $uhttp({
                url: api_url + controller + 'recharge_tag',
                method: "POST",
                data: data,
                params: {
                    id: tag_id
                }
            });
        };
    }
]);