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

const { String:EmberString, computed } = Ember;
const { Model, attr, belongsTo, hasMany } = DS;
const { htmlSafe } = EmberString;

export default Model.extend({
  title: attr('string'),
  calendarColor: attr('string'),
  active: attr('boolean'),
  assessment: attr('boolean'),
  assessmentOption: belongsTo('assessment-option', {async: true}),
  school: belongsTo('school', {async: true}),
  aamcMethods: hasMany('aamc-method', {async: true}),
  sessions: hasMany('session', {async: true}),
  safeCalendarColor: computed('calendarColor', function(){
    const calendarColor = this.get('calendarColor');
    const pattern = new RegExp("^#[a-fA-F0-9]{6}$");
    if (pattern.test(calendarColor)) {
      return htmlSafe(calendarColor);
    }

    return '';

  }),
  sessionCount: computed('sessions.[]', function(){
    const sessons = this.hasMany('sessions');

    return sessons.ids().length;
  })
});

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

const { String:EmberString, computed } = Ember;
const { Model, attr, belongsTo, hasMany } = DS;
const { htmlSafe } = EmberString;

export default Model.extend({
  title: attr('string'),
  calendarColor: attr('string'),
  active: attr('boolean'),
  assessment: attr('boolean'),
  assessmentOption: belongsTo('assessment-option', {async: true}),
  school: belongsTo('school', {async: true}),
  aamcMethods: hasMany('aamc-method', {async: true}),
  sessions: hasMany('session', {async: true}),
  safeCalendarColor: computed('calendarColor', function(){
    const calendarColor = this.get('calendarColor');
    const pattern = new RegExp("^#[a-fA-F0-9]{6}$");
    if (pattern.test(calendarColor)) {
      return htmlSafe(calendarColor);
    }

    return '';

  }),
  sessionCount: computed('sessions.[]', function(){
    const sessons = this.hasMany('sessions');

    return sessons.ids().length;
  }),
  firstAamcMethod: computed('aamcMethods.[]', async function(){
    const aamcMethods = await this.get('aamcMethods');
    return aamcMethods.get('firstObject');
  }),
});

Add firstAamcMethod to sessionType model
Add firstAamcMethod to sessionType model

This has been added to the frontend since the extraction happened.
