Module 				= window.require 'spine/core/module'
Events 				= window.require 'spine/core/events'
Entry 				= require '../model/entry'

class Service extends Module
	@browser: 'browser/controller'
	@authenticating: false
	@include Events

	constructor: (title,options)->
		super
		@title = title
		@root = new Entry type:'folder', path:'/', root:true
		@options = options
		@listenTo @, 'auth', => clearTimeout @authFailInterval

	###
	The abstract auth function calls the _auth implementation function.
	Rate-limited at 300 ms.
	###
	auth: ->
		# console.log("Service auth:", @authenticating)
		return if @authenticating
		@authenticating = true
		setTimeout (=>@authenticating = false), 300

		clearTimeout @authFailInterval
		@authFailInterval = setTimeout =>
			@trigger 'auth', @authenticated = false
		, 3000

		@_auth arguments...

module.exports = Service
