const clone = require('clone');
const tv4 = require('tv4');

class Settings {
  constructor(opt) {
    this._id = null;
    this.hasLoggedIn = null;

    if (opt) {
      this.fillObject(clone(opt));
    }
  }

  fillObject(opt) {
    this._id = opt._id;
    this.hasLoggedIn = opt.hasLoggedIn;
  }

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

  static schema() {
    return {
      $schema: 'http://json-schema.org/draft-04/schema#',
      id: 'settings.schema.json',
      type: 'object',
      additionalProperties: false,
      properties: {
        _id: { type: 'string' },
        hasLoggedIn: { type: 'boolean' },
      },
      required: Object.keys(this),
    };
  }
}

module.exports = Settings;
