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

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

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

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

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

		@_auth arguments...

module.exports = Service
