'use strict';

const FieldModelGenerator = require('./FieldModelGenerator-1af8e5c3.js');
const dataModel = require('./data-model-9afb7f54.js');

function decodeFields(fieldData = []) {
  return fieldData.map(fd => FieldModelGenerator.generateFieldModelFromRawData(fd));
}

class Space extends dataModel.DataModel {
  static decode(json) {
    return Object.assign(Object.create(Space.prototype), json);
  }
}

class TableConfig extends dataModel.DataModel {
  static decode(json) {
    const model = Object.assign(Object.create(TableConfig.prototype), json);
    model.space = Space.decode(model.space);
    model.fields = decodeFields(model.fields);
    return model;
  }
}

exports.Space = Space;
exports.TableConfig = TableConfig;
exports.decodeFields = decodeFields;
