import Ember from 'ember';
import DS from 'ember-data';

export default DS.Model.extend({
  races: DS.hasMany('race'),
  name: DS.attr('string'),
  city: DS.attr('string'),
  state: DS.attr('string', {
    defaultValue: 'AL'
  }),
  country: DS.attr('string', {
    defaultValue: 'US'
  }),
  lat: DS.attr('number'),
  lon: DS.attr('number'),
  // start date (some events are multiple days and will have an end date)
  startTime: DS.attr('number'),
  startDate: Ember.computed('startTime', {
    get() {
      return new Date(this.get('startTime'));
    },
    set(key, value) {
      this.set('startTime', (new Date(value)
        .getTime()));
      return value;
    }
  }),
  endTime: DS.attr('number'),
  endDate: Ember.computed('endTime', {
    get() {
        return new Date(this.get('endTime'));
    },
    set(key, value) {
      this.set('endTime', (new Date(value)
        .getTime()));
      return value;
    }
  }),
  url: DS.attr('string'),
  saveWithGeo: function() {
    const city = this.get('city');
    const state = this.get('state');
    Ember.$.ajax(`http://nominatim.openstreetmap.org/search?format=json&city=${city}&state=${state}&limit=1`)
      .then((response) => {
        const geo = response[0];
        this.set('lat', geo.lat);
        this.set('lon', geo.lon);
        this.save();
      });
  }
});

@@ -754,26 +754,24 @@
 t() %7B%0A      
-  
 return new D
@@ -788,32 +788,32 @@
 et('endTime'));%0A
+
     %7D,%0A    set(k
@@ -965,18 +965,8 @@
 hGeo
-: function
 () %7B
@@ -1190,19 +1190,21 @@
   const 
+%5B
 geo
+%5D
  = respo
@@ -1210,11 +1210,8 @@
 onse
-%5B0%5D
 ;%0A  

Address JSHint errors