{"size": 902, "ext": "js", "max_stars_repo_path": "app/services/attestation-validator.js", "max_stars_repo_name": "chasballew/dashboard.aptible.com", "max_stars_repo_stars_event_min_datetime": "2015-04-27T22:58:02.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-21T18:52:06.000Z", "max_issues_repo_path": "app/services/attestation-validator.js", "max_issues_repo_name": "chasballew/dashboard.aptible.com", "max_issues_repo_issues_event_min_datetime": "2015-04-14T13:48:47.000Z", "max_issues_repo_issues_event_max_datetime": "2017-09-29T14:01:31.000Z", "max_forks_repo_path": "app/services/attestation-validator.js", "max_forks_repo_name": "chasballew/dashboard.aptible.com", "max_forks_repo_forks_event_min_datetime": "2015-06-02T16:11:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-09-27T05:41:35.000Z"}
{"max_stars_count": 80, "max_issues_count": 380, "max_forks_count": 38, "avg_line_length": 25.0555555556, "max_line_length": 89, "alphanum_fraction": 0.6297117517}
import Ember from 'ember';

export default Ember.Service.extend({
  validate(attestation, schemaDocument) {
    let validator = this.validators[attestation.get('handle')] || this.validators.global;
    return validator(schemaDocument);
  },

  validators: {
    global() {
      return [];
    },

    workforce_locations() {
      return [];
    },

    workforce_roles(schemaDocument) {
      // TODO: Can this type of validation be done using JSON schema?
      // May have to inverse schema so developers and security officers are
      // arrays.
      let errors = [];

      if (schemaDocument.filterBy('isDeveloper', true).length === 0) {
        errors.push('at least one Developer is required');
      }

      if (schemaDocument.filterBy('isSecurityOfficer', true).length === 0) {
        errors.push('at least one Security Officer is required');
      }

      return errors;
    }
  }
});
