define('ember-resource-metadata/services/resource-metadata', ['exports', 'ember-resource-metadata/private-api'], function (exports, _privateApi) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.default = Ember.Service.extend({
    store: Ember.inject.service(),

    init: function init() {
      this._super();
      this.metastore = new _privateApi.WeakMap();
    },
    _identityFor: function _identityFor(thing) {
      var identity = (0, _privateApi.extractIdentityKey)(thing);
      if (!identity) {
        var type = Ember.get(thing, 'type');
        var id = Ember.get(thing, 'id');
        identity = (0, _privateApi.lookupIdentityKey)(this.get('store'), type, id);
      }
      return identity;
    },
    write: function write(thing, metadata) {
      var identity = this._identityFor(thing);
      var existing = this.metastore.get(identity);
      if (existing) {
        Ember.setProperties(existing, metadata);
      } else {
        this.metastore.set(identity, Ember.Object.create(metadata));
      }
    },
    read: function read(thing) {
      var identity = this._identityFor(thing);
      var meta = this.metastore.get(identity);
      if (!meta) {
        meta = Ember.Object.create();
        this.metastore.set(identity, meta);
      }
      return meta;
    },
    peek: function peek(thing) {
      var identity = this._identityFor(thing);
      return this.metastore.get(identity);
    }
  });
});