 class Model
     constructor: (source_data) ->
         @_data = source_data
+        @_keys = []
         @_configureProperties()
+        
 
     _configureProperties: ->
         for k,v of @_data

            configurable : true

    toJSON: -> @_data

    get: (name) ->
        # Don't try to make the entry contents into Models

    LOCATION    : LOCATION
    TOPIC       : TOPIC

normalizeContentData = (all_collections) ->
    object_index = new Map()
    all_collections.forEach (collection) ->
        collection.forEach (model) ->
            object_index.set(model.id, model)

    _getFromIndex = (obj_or_id) ->
        if not obj_or_id
            return
        if obj_or_id.id
            return object_index.get(obj_or_id.id)
        return object_index.get(obj_or_id)

    all_collections.forEach (collection) ->
        collection.forEach (model) ->
            model.keys().forEach (key) ->
                unless model[key]
                    return
                _type = key.split('_').pop()

                if _type in ['content', 'entities', 'entity'] and not (model.type is ENTRY and key is 'content')
                    if Array.isArray(model[key])
                        model[key] = model[key].map(_getFromIndex)
                    else if typeof model[key] is 'object'
                        if model[key].id
                            if object_index[model[key].id]
                                model[key] = object_index.get(model[key].id)
                            else
                                console.warn 'UNKNOWN?', key, model[key]
                        else
                            Object.keys(model[key]).forEach (k) ->
                                model[key][k] = _getFromIndex(model[key][k])
                    else if typeof model[key] is 'string' and object_index.get(model[key])
                        model[key] = object_index.get(model[key])

    [entries, packages, people, locations, topics] = all_collections
    return { entries, packages, people, locations, topics }


module.exports              = ContentAPI
module.exports.CDNImage     = CDNImage
module.exports.Model        = Model
