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

class FacilityBuilding {
  constructor(opt) {
    this.buildingId = null;
    this.buildingName = null;
    this.address = null;

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

  fillObject(opt) {
    this.buildingId = opt.buildingId || null;
    this.buildingName = opt.buildingName || null;
    this.address = opt.address || null;
  }

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

  static schema() {
    const building = new FacilityBuilding();
    const requiredFacilityBuilding = Object.keys(building);

    return {
      $schema: 'http://json-schema.org/draft-04/schema#',
      id: 'facility-building.schema.json',
      type: 'object',
      additionalProperties: false,
      properties: {
        buildingId: { type: 'string' },
        buildingName: { type: 'string' },
        address: { type: ['string', 'null'] },
      },
      required: requiredFacilityBuilding,
    };
  }
}

module.exports = FacilityBuilding;
