import java.*
import groovy.*
import css
import javascript.jQuery

if(!candidate.ambitious) throw new InterviewFailedException()

def requirements = new TestRunner(Requirements).run()
if(!requirements.passed) throw new InterviewFailedException()

println "Suitable candidate identified."
println "(Bonus points: ${calculateBonusPoints()})"
println "Please apply for job immediately."

class Requirements {
	@Test
	void "candidate should have programming experience"() {
		assert programming in candidate.experience
	}

	@Test
	void "candidate should have led great dev teams"() {
		assert candidate.pastTeams.findAll { 
			it.leader == candidate 
		}.every { it.awesome }
	}

	@Test
	void "candidate should like writing good code"() {
		assert [OOP, TDD, "clean code"].every {
			it in candidate.interests
		}
	}

	@Test
	void "candidate should know a thing or two about cloud-hosted SaaS"() {
		assert ["AWS", "ZeroDowntimeDeployment", "ContinuousDelivery"].every {
			it in candidate.interests
		}
	}
	
	@Test
	void "candidate should be interested in JVM languages"() {
		assert [groovy, scala, kotlin].inject(0) { lang, t ->
			t + candidate.interests.lang
		}
	}
}

class FrontlineSMS {
	def about = '''
FrontlineSMS are the makers of FrontlineCloud, best-in-class
messaging management and automation software. We work with the tools
and processes above to delivery impactful projects with partners around
the world. We are looking for a new CTO to lead our dev team based in
the iHub in Nairobi. If this sounds like you, apply now!

'''
	def methodology = agile * scrum * kanban
	def sourceControl = git
	def frameworks = [grails, jQuery]
	def tools = [AWS, jenkins]

	def devTeam = ['Vaneyck', 'Allan', 'Kenneth', 'Ahmed', 'Sitati']
	def location = 'Nairobi'

	def contact = [
		email: 'join-the-team+cto@frontlinesms.com',
		web: 'http://www.frontlinesms.com'
	]
}

def calculateBonusPoints() {
	def bonusPoints

	// front-end experience desirable
	[CSS, javascript, jQuery].each {
		if(candidate.experience.contains(it))
			++bonusPoints
	}

	// interest in impactful technology desirable
	if('social impact' in candidate.interests)
		++bonusPoints

	if('saw this ad, mentioned it' in candidate.coverLetter)
		++bonusPoints

	// mobile development experience desirable
	[android, kotlin].each {
		if(candidate.experience.contains(it))
			++bonusPoints
	}
}