 # 14  2 Plat,               17000000,   13900
 # 15  3 Plat,               24000000,   14200
 # 16  4 Plat, 2 Black,      40000000,   14400
+
+levels =
+  1:
+    ap: 0
+    xm: 3000
+  2:
+    ap: 10000
+    xm: 4000
+  3:
+    ap: 30000
+    xm: 5000
+  4:
+    ap: 70000
+    xm: 6000
+  5:
+    ap: 150000
+    xm: 7000
+  6:
+    ap: 300000
+    xm: 8000
+  7:
+    ap: 600000
+    xm: 9000
+  8:
+    ap: 1200000
+    xm: 10000
+  9:
+    ap: 2400000
+    xm: 10900
+    badges:
+      silver: 4
+      gold: 1
+  10:
+    ap: 4000000
+    xm: 11700
+    badges:
+      silver: 5
+      gold: 2
+  11:
+    ap: 6000000
+    xm: 12400
+    badges:
+      silver: 6
+      gold: 4
+  12:
+    ap: 8400000
+    xm: 13000
+    badges:
+      silver: 7
+      gold: 6
+  13:
+    ap: 12000000
+    xm: 13500
+    badges:
+      gold: 7
+      platinum: 1
+  14:
+    ap: 17000000
+    xm: 13900
+    badges:
+      platinum: 2
+  15:
+    ap: 24000000
+    xm: 14200
+    badges:
+      platinum: 3
+  16:
+    ap: 40000000
+    xm: 14400
+    badges:
+      platinum: 4
+      black: 2
 
 badgeList = [
   'builder1', 'builder2', 'builder3', 'builder4', 'builder5',

module.exports = (robot) ->
  badges = {}

  robot.brain.on "loaded", ->
    badges = robot.brain.data.ingressBadges ?= {}

  robot.respond /AP\s+(?:to|(?:un)?til)\s+L?(\d{1,2})/i, (msg) ->
    lv = msg.match[1]
    ap = apToLv[lv]
    msg.reply "You need #{ap} AP to reach L#{lv}" if ap

  robot.respond /AP all/i, (msg) ->
    msg.send "L#{i+1} = #{ap} AP" for ap, i in apToLv.slice 1

  robot.respond /(I|@?\w+) (?:have|has|got|earned)(?: the)? :?(\w+):? badge/i, (msg) ->
    who = msg.match[1].replace '@', ''

# Author:
#   therealklanni

# Quick refrence for what badges are need at what level
# LVL   Badges              AP          Max xm
# 9   4 Silver, 1 Gold,     2400000,    10900
