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

class CardLabelValue {
  constructor(opt) {
    this.label = null;
    this.value = null;

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

  fillObject(opt) {
    this.label = opt.label;
    this.value = opt.value || null;
  }

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

  static schema() {
    return {
      $schema: 'http://json-schema.org/draft-04/schema#',
      id: 'card-label-value.schema.json',
      type: 'object',
      additionalProperties: false,
      properties: {
        label: { type: 'string' },
        value: { type: ['string', 'null'] },
      },
      required: Object.keys(this),
    };
  }
}

module.exports = CardLabelValue;
