
(function () {
    'use strict';
   angular.module('Monitour.pages.profile')
        .factory('ProfileService', ProfileService);
 
    function ProfileService($http, $localStorage) {

	     var service = {};
       
	    service.GetAll = GetAll;
        service.GetById = GetById;
        service.Update = Update;
        service.Delete = Delete;
		service.MediaUpload = MediaUpload;
		service.MediaDownload = MediaDownload;
		service.MediaDownloadId = MediaDownloadId;
		service.MediaDeleteId = MediaDeleteId;
		service.Labels = Labels;
		service.GetLabels = GetLabels;
		service.UpdateLabels = UpdateLabels;
	
		
 
 
      
	   var domain  = 'https://api.callio.com.au/public/';
	   
	   return service;
		
		 function GetAll() {
			   
            return $http.get(domain + 'users/me').then(handleSuccess, handleError('Error getting your profile by id'));
        }
		
      
        function GetById(id) {
            return $http.get(domain + 'users' + id).then(handleSuccess, handleError('Error getting your profile by id'));
        }
       
	   
	   function MediaUpload(picture) {
		    
            return $http.post(domain + 'image/upload', picture ).then(handleSuccess, handleError('Error getting your media by picture'));
        }
		
		
		   function MediaDownload() {
		    
            return $http.get(domain + 'image/download').then(handleSuccess, handleError('Error getting your media by picture'));
        }
        
		  function MediaDownloadId(id) {
		    
            return $http.get(domain + 'image/download/' + id).then(handleSuccess, handleError('Error getting your media by picture'));
        }
        
        
		 function Labels(label) {		    
            return $http.post(domain + 'labels', label ).then(handleSuccess, handleError('Error posting your label'));
        }
		
		function GetLabels() {
			   
            return $http.get(domain + 'labels').then(handleSuccess, handleError('Error getting your profile by id'));
        }
		
		  function UpdateLabels(data, id) {
            return $http.patch(domain + 'labels/' + id, data).then(handleSuccess, handleError('Error updating profile'));
        }
		
        function Update(profile, id) {
            return $http.patch(domain + 'userupdate/' + id, profile).then(handleSuccess, handleError('Error updating profile'));
        }
   

        function Delete(id) {
            return $http.delete(domain + 'users' + id).then(handleSuccess, handleError('Error deleting route'));
        }
         
		 function MediaDeleteId(id) {
            return $http.delete(domain + 'media/' + id).then(handleSuccess, handleError('Error deleting route'));
        }
        // private functions
 
        function handleSuccess(res) {
            return res.data;
        }
 
        function handleError(error) {
            return function () {
                return { success: false, message: error };
            };
        }
    }
 
})();