const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const event_streams = sequelize.define(
    'event_streams',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

stream_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"nats_subject",


"kafka_topic",


"jetstream_stream"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

subject_or_topic: {
        type: DataTypes.TEXT,
      
      

      },

retention_policy: {
        type: DataTypes.ENUM,
      
      

        values: [

"limits",


"interest",


"workqueue",


"compact"

        ],

      },

retention_days: {
        type: DataTypes.INTEGER,
      
      

      },

stream_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"paused",


"error"

        ],

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  event_streams.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity





















































    db.event_streams.hasMany(db.conference_events, {
      as: 'conference_events_event_stream',
      foreignKey: {
          name: 'event_streamId',
      },
      constraints: false,
    });



//end loop



    db.event_streams.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

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




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

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



  return event_streams;
};


