module.exports = function(sequelize, DataTypes) {
  const vorta_universe_states = sequelize.define(
    'vorta_universe_states',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      profile: {
        type: DataTypes.JSONB,
        allowNull: false,
        defaultValue: {},
      },
      modules: {
        type: DataTypes.JSONB,
        allowNull: false,
        defaultValue: [],
      },
      products: {
        type: DataTypes.JSONB,
        allowNull: false,
        defaultValue: [],
      },
      ledger: {
        type: DataTypes.JSONB,
        allowNull: false,
        defaultValue: [],
      },
      settings: {
        type: DataTypes.JSONB,
        allowNull: false,
        defaultValue: {},
      },
      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  vorta_universe_states.associate = (db) => {
    db.vorta_universe_states.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.vorta_universe_states.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });

    db.vorta_universe_states.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.vorta_universe_states.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };

  return vorta_universe_states;
};
