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

const Card = require('./card');

class BiosafetyCard extends Card {
  constructor(opt) {
    super(opt);
    this.type = 'BIOSAFETY';
    this.details = {
      _id: null,
      seriesId: null,
    };

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

  fillObject(details) {
    this.details._id = details._id || null;
    this.details.seriesId = details.seriesId || null;
  }

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

  static schema() {
    return {
      $schema: 'http://json-schema.org/draft-04/schema#',
      id: 'bua-card.schema.json',
      type: 'object',
      allOf: [
        { $ref: 'card.schema.json' },
        {
          properties: {
            details: {
              _id: { type: ['string', 'null'] },
              seriesId: { type: ['string', 'null'] },
            },
          },
        },
      ],
      required: Object.keys(new BiosafetyCard()),
    };
  }
}

tv4.addSchema(Card.schema());

module.exports = BiosafetyCard;
