module.exports = function(sequelize, DataTypes) {
  const plans = sequelize.define(
    'plans',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      name: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      price: {
        type: DataTypes.DECIMAL(10, 2),
        allowNull: false,
        defaultValue: 0,
      },
      features: {
        type: DataTypes.JSONB,
        allowNull: true,
      },
    },
    {
      timestamps: true,
    },
  );

  plans.associate = (db) => {
    db.plans.hasMany(db.businesses, {
      as: 'businesses',
      foreignKey: 'planId',
    });
  };

  return plans;
};
