var forEach=Ember.EnumerableUtils.forEach;DS.EmbeddedAdapter=DS.RESTAdapter.extend(DS.UnderscoredAdapterMixin,{defaultSerializer:"_embedded",ajaxError:function(e){var t=this._super(e),i={};if(e&&422===e.status){var r=Ember.$.parseJSON(e.responseText).errors;return forEach(Ember.keys(r),function(e){i[Ember.String.camelize(e)]=r[e]}),new DS.InvalidError(i)}return e&&404===e.status?(i[404]="Not Found",new DS.InvalidError(i)):t}}),DS.EmbeddedInModel=DS.Model.extend(DS.EmbeddedInModelMixin),DS.EmbeddedSerializer=DS.RESTSerializer.extend(DS.UnderscoredSerializer,DS.EmbeddedMixin),Ember.onLoad("Ember.Application",function(e){e.initializer({name:"embeddedAdapter",initialize:function(e,t){t.register("serializer:_embedded",DS.EmbeddedSerializer),t.register("adapter:_embedded",DS.EmbeddedAdapter)}})}),DS.ModelWithEmbedded=DS.Model.extend(DS.ModelWithEmbeddedMixin),function(e,t){function i(){var t=this;e.run(function(){t.transitionTo("updated.uncommitted")})}var r="currentState.stateName";t.EmbeddedInModelMixin=e.Mixin.create({embeddedDirtyTracker:function(){if(this.get("isDirty")){var e=this;this.eachRelationship(function(t){if("function"!=typeof this.then){var r=e.get(t);!r||r.get("isLoading")||r.get("isDirty")||i.call(r)}})}}.observes(r)})}(Ember,DS),function(e,t){function i(e){return e&&("always"===e.embedded||"load"===e.embedded)}function r(e){return e&&"ids"===e.embedded}function n(e,t){var i=e+"_id";t.hasOwnProperty(i)&&delete t[i]}function a(e,t,r,n){var a=d(this,"attrs");a&&t.eachRelationship(function(t,d){var l=a[t];i(l)&&("hasMany"===d.kind&&o.call(this,e,t,d,r,n),"belongsTo"===d.kind&&s.call(this,e,t,d,r,n))},this)}function o(t,i,r,n,o){var s=t.serializerFor(r.type.typeKey),u=d(this,"primaryKey"),c=r.type.typeKey,h="_"+e.String.pluralize(c),y=this.keyForRelationship(i,r.kind),p=this.keyForAttribute(i),f=[];o[p]&&(n[h]=n[h]||[],l(o[p],function(e){var i=t.modelFor(c);a.call(s,t,i,n,e),f.push(e[u]),n[h].push(e)}),o[y]=f,delete o[p])}function s(t,r,n,o,s){var l=this.get("attrs");if(l&&(i(l[e.String.camelize(r)])||i(l[r]))){var u=n.type.typeKey,c=t.serializerFor(n.type.typeKey),h=(d(c,"primaryKey"),e.String.pluralize(u)),y=c.keyForRelationship(r,n.kind),p=c.keyForAttribute(r);if(s[p]){o[h]=o[h]||[];var f=t.modelFor(n.type.typeKey);for(var m in s)s.hasOwnProperty(m)&&m.camelize()===u&&a.call(c,t,f,o,s[m]);s[y]=s[p].id,o[h].push(s[p]),s[p][n.parentType.typeKey+"_id"]=s.id,delete s[p]}}}var d=e.get,l=e.EnumerableUtils.forEach;t.EmbeddedMixin=e.Mixin.create({serializeBelongsTo:function(e,t,r){var a=r.key,o=this.get("attrs");if(!o||!i(o[a]))return void this._super(e,t,r);var s=this.keyForAttribute(a),d=e.get(a);if(d){t[s]=d.serialize();var l=d.get("id");l&&(t[s].id=l);var u=this.keyForAttribute(r.parentType.typeKey);u&&n(u,t[s]),delete t[s][u]}else t[s]=null},serializeHasMany:function(e,t,n){var a,o=n.key,s=this.get("attrs");return s&&(i(s[o])||r(s[o]))?void(r(s[o])?(a=this.keyForRelationship(o,n.kind),t[a]=d(e,o).mapBy(d(this,"primaryKey"))):(a=this.keyForAttribute(o),t[a]=d(e,o).map(function(e){var t=e.serialize(),i=d(this,"primaryKey");return t[i]=d(e,i),null===t.id&&delete t.id,t},this))):void this._super(e,t,n)},extractSingle:function(e,t,i,r,n){var o=this.keyForAttribute(t.typeKey),s=i[o];return a.call(this,e,t,i,s),this._super(e,t,i,r,n)},extractArray:function(t,i,r){var n=this.keyForAttribute(i.typeKey),o=r[e.String.pluralize(n)];return l(o,function(e){a.call(this,t,i,r,e)},this),this._super(t,i,r)}})}(Ember,DS),function(e,t){function i(e){return e&&("always"===e.embedded||"load"===e.embedded)}function r(e,t,r){var n=u(this.constructor,"relationshipsByName"),a=n.values;for(var o in a)if(a.hasOwnProperty(o)){var s=a[o].key;e&&i(e[t.keyForAttribute(s)])&&r(a[o],this.get(s))}}function n(e,t){if(t&&!a(t)){var i=e.kind;"belongsTo"===i?o(t):"hasMany"===i&&t.content.forEach(o)}}function a(e){return"function"==typeof e.then}function o(t){null===t.get(c).match(/saved/)&&e.run(function(){t.rollback()})}function s(e,t){if(t&&!a(t)){var i=e.kind;"belongsTo"===i?d(t):"hasMany"===i&&t.content.forEach(d)}}function d(e){return a(this)?this:void(e.get("isLoading")||e.get("isDirty")||l.call(e))}function l(){var t=this;e.run(function(){t.transitionTo("updated.uncommitted")})}var u=e.get,c="currentState.stateName";t.ModelWithEmbeddedMixin=e.Mixin.create({embeddedNotifier:function(e,t){var i=this.store.serializerFor(this.constructor),a=i.get("attrs");a&&("root.loaded.updated.uncommitted"===this.get(t)?r.call(this,a,i,s):"root.loaded.saved"===this.get(t)&&r.call(this,a,i,n))}.observes(c)})}(Ember,DS),function(e,t){t.UnderscoredAdapterMixin=e.Mixin.create({pathForType:function(t){var i=e.String.decamelize(t);return e.String.pluralize(i)}})}(Ember,DS),function(e,t){var i=e.get,r=e.EnumerableUtils.forEach;t.UnderscoredSerializer=e.Mixin.create({keyForAttribute:function(t){return e.String.decamelize(t)},keyForRelationship:function(t,i){return t=e.String.decamelize(t),"belongsTo"===i?t+"_id":"hasMany"===i?e.String.singularize(t)+"_ids":t},serializeIntoHash:function(t,i,r,n){var a=e.String.decamelize(i.typeKey);t[a]=this.serialize(r,n)},serializePolymorphicType:function(t,r,n){var a=n.key,o=i(t,a);o&&(a=this.keyForAttribute(a),r[a+"_type"]=e.String.capitalize(o.constructor.typeKey))},typeForRoot:function(t){var i=e.String.camelize(t);return e.String.singularize(i)},normalize:function(e,t,i){return this.normalizeLinks(t),this._super(e,t,i)},normalizeLinks:function(t){if(t.links){var i=t.links;for(var r in i){var n=e.String.camelize(r);n!==r&&(i[n]=i[r],delete i[r])}}},normalizeRelationships:function(e,t){var i,n;this.keyForRelationship&&e.eachRelationship(function(e,a){if(a.options.polymorphic){if(i=this.keyForAttribute(e),n=t[i],n&&n.type)n.type=this.typeForRoot(n.type);else if(n&&"hasMany"===a.kind){var o=this;r(n,function(e){e.type=o.typeForRoot(e.type)})}}else i=this.keyForRelationship(e,a.kind),n=t[i];t[e]=n,e!==i&&delete t[i]},this)}})}(Ember,DS);