import Ember from 'ember';

const {
  Service,
  get,
  set
} = Ember;

export default Service.extend({
  init() {
    this._super(...arguments);
    let config = Ember.getOwner(this).application.resolveRegistration('config:environment').hoodie.client
    let hoodie = new Hoodie(config);
    set(this, 'hoodie', hoodie);
    // for debug only
    window.hoodie = hoodie;
  },

  unknownProperty(keyName) {
    let hoodie = get(this, 'hoodie');
    if (keyName in hoodie) {
      return hoodie[keyName];
    } else {
      this._super(...arguments);
    }
  }
});

import Ember from 'ember';

const {
  Service,
  get,
  set
} = Ember;

export default Service.extend({
  init() {
    this._super(...arguments);
    const appConfig = Ember.getOwner(this).application.resolveRegistration('config:environment')
    const hoodieConfig = appConfig.hoodie ? appConfig.hoodie.client : {}
    const hoodie = new Hoodie(hoodieConfig);
    set(this, 'hoodie', hoodie);
    // for debug only
    window.hoodie = hoodie;
  },

  unknownProperty(keyName) {
    const hoodie = get(this, 'hoodie');
    if (keyName in hoodie) {
      return hoodie[keyName];
    } else {
      this._super(...arguments);
    }
  }
});

make ENV.hoodie.client config optional