import BaseModel from './BaseModel';
import is from 'is_js';

export default class extends BaseModel {
  defaults() {
    return {
      peerID: '',
      type: '',
    };
  }

  get idAttribute() {
    return 'peerID';
  }

  parse(response) {
    // if the response is not an object, assume it is a peerID and convert it
    // this accounts for providers that only give a list of ids
    const parsedResponse = (!!response) && (response.constructor === Object) ? response :
      { peerID: response };
    return parsedResponse;
  }

  validate(attrs) {
    const errObj = {};
    const addError = (fieldName, error) => {
      errObj[fieldName] = errObj[fieldName] || [];
      errObj[fieldName].push(error);
    };

    if (!attrs.name) {
      addError('peerID', 'peerID must be provided');
    } else if (is.not.string(attrs.peerID)) {
      addError('peerID', 'peerID must be a string.');
    }

    if (Object.keys(errObj).length) return errObj;

    return undefined;
  }
}

@@ -33,32 +33,8 @@
 el';
-%0Aimport is from 'is_js';
 %0A%0Aex
@@ -196,765 +196,7 @@
 %0A  %7D
-%0A%0A  parse(response) %7B%0A    // if the response is not an object, assume it is a peerID and convert it%0A    // this accounts for providers that only give a list of ids%0A    const parsedResponse = (!!response) && (response.constructor === Object) ? response :%0A      %7B peerID: response %7D;%0A    return parsedResponse;%0A  %7D%0A%0A  validate(attrs) %7B%0A    const errObj = %7B%7D;%0A    const addError = (fieldName, error) =%3E %7B%0A      errObj%5BfieldName%5D = errObj%5BfieldName%5D %7C%7C %5B%5D;%0A      errObj%5BfieldName%5D.push(error);%0A    %7D;%0A%0A    if (!attrs.name) %7B%0A      addError('peerID', 'peerID must be provided');%0A    %7D else if (is.not.string(attrs.peerID)) %7B%0A      addError('peerID', 'peerID must be a string.');%0A    %7D%0A%0A    if (Object.keys(errObj).length) return errObj;%0A%0A    return undefined;%0A  %7D
 %0A%7D%0A

remove unneeded model code