       for name of data
         value = data[name]
         add = (d) =>
-          type = TYPES[name] || name
+          type = @types[name] || name
           @remove type, d.id
           @records.push new Record(type: type, data: d)
 


module.exports = (utils) ->

  # TODO: move to config
  TYPES =
    'events': 'event'
    'ticketBatches': 'ticketBatch'
    'images': 'image'
    'tickets': 'ticket'
    'sponsors': 'sponsor'
    'sponsorLevels': 'sponsorLevel'
    'speakers': 'speaker'
    'organisers': 'organiser'
    'payments': 'payment'


  class Record
    constructor: (options) ->
      @type = options.type
      @data = options.data

  class Store
    constructor: (options) ->

    setupRelations: (links) ->
      for key, value of links
        [type, attribute] = key.split '.'
        type = @types[type] || type
        @relations[type] ||= {}
        @relations[type][attribute] = @types[value.type] || value.type

    findRecord: (type, id) ->
      utils.find @records, (r) ->
