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

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

class BuaCard extends Card {
  constructor(opt) {
    super(opt);
    this.type = 'BUA';
    this.details = {
      buaId: null,
    };

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

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

  validate() {
    return tv4.validateMultiple(this, BuaCard.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: {
              buaId: { type: ['string', 'null'] },
            },
          },
        },
      ],
      required: Object.keys(this),
    };
  }
}

tv4.addSchema(Card.schema());

module.exports = BuaCard;
