//  @import com.hedgehoglab.application.service.BaseService;
//  @import com.hedgehoglab.events.Thread;

function LicenceService(scope){
	BaseService.call(this,scope);
	var _is_valid_licence=false;
	var _this=this;
	
	var _subcribe_to=_this.subscribe_to;
	
	// this.subcribe_to=function(message,callback){
	// 	//	Subscribe th
	// }
	
	
	//	Make a call to the backend to check the licence satus
	//	http://localhost:8080/api/backend/check-valid-license
	function check_is_valid_licence(callback){
		_this.request({
	        uri:"/api/backend/check-valid-license"
	        ,data:null
	        ,type:"GET"
			,async:false
	        ,callback:function(e){                
	            _is_valid_licence=(e.success!=null)?true:false;
	        }
	    });
		
	}
	
	// http://localhost:8080/api/backend/permissions/add-user	
	this.can_add_users=function(callback){
		_this.request({
	        uri:"/api/backend/permissions/add-user"
	        ,data:null
	        ,type:"GET"
			,async:false
	        ,callback:function(e){                
	            _can_add_users=(e.success!=null)?true:false;
				callback(_can_add_users,e);
	        }
	    });
	};
	
	this.can_add_contacts=function(callback){
		_this.request({
	        uri:"/api/backend/permissions/add-contact"
	        ,data:null
	        ,type:"GET"
			,async:false
	        ,callback:function(e){                
	            _can_add_contacts=(e.success!=null)?true:false;
				callback(_can_add_contacts,e);
	        }
	    });
	};
	
	this.is_valid_licence=function(callback,explicit){
		check_is_valid_licence();
		// if(explicit){
		// 		//	Make another call backend to check
		// 		//	callback with status to notify
		// 		// _thread.stop();
		// 		check_is_valid_licence();
		// 		callback(_is_valid_licence);
		// 			//_this.raise_event('on_licence_check_complete',_is_valid_licence);
		// 			// _thread.start(scope.interval*1000);
		// 		
		// 	}else{
			// _this.raise_event('on_licence_check_complete',_is_valid_licence);
			callback(_is_valid_licence);
		// }
	};
	//	Poll the server every 5 seconds to check the status of licence
	//	or! when a request is made, notify 
	// check_is_valid_licence();
	
	
	// var _thread=new Thread(function(e){
		check_is_valid_licence();
	// });

	//	Start the thread
	// _thread.start(scope.interval*1000);
}