const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
  const EventPlace = sequelize.define('EventPlace', {
    name: {
      type: DataTypes.STRING,
      allowNull: false
    },
    street: {
      type: DataTypes.STRING,
      allowNull: false
    },
    zipcode: {
      type: DataTypes.STRING,
      allowNull: false
    },
    city: {
      type: DataTypes.STRING,
      allowNull: false
    },
    backgroundColor: {
      type: DataTypes.STRING,
      allowNull: true
    },
    website: {
      type: DataTypes.STRING,
      allowNull: true
    },
  }, {
    tableName: 'event_places'
  });

  EventPlace.associate = function(models) {
    EventPlace.hasMany(models.Event, {
      foreignKey: 'event_place_id',
      as: 'events'
    });
  };

  return EventPlace;
};
