const tv4 = require('tv4');

const { EDGE } = require('../../constant/relationship/label.constant');

class Role {
  constructor(opt = {}) {
    this.id = null;
    this.name = null;
    this.active = null;

    this.fillObject(opt);
  }

  fillObject(opt) {
    this.id = opt.id || null;
    this.name = opt.name || null;
    this.active = opt.active || true;
  }

  validate() {
    return tv4.validateMultiple(this, Role.schema());
  }

  static schema() {
    return {
      $schema: 'http://json-schema.org/draft-04/schema#',
      id: 'role.schema.json',
      type: 'object',
      additionalProperties: false,
      properties: {
        id: { type: 'number' },
        name: { enum: Object.keys(EDGE) },
        active: { type: 'boolean' },
      },
      required: Object.keys(new Role()),
    };
  }
}

tv4.addSchema(Role.schema());

module.exports = Role;
