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 participants = sequelize.define(
    'participants',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

display_name: {
        type: DataTypes.TEXT,
      
      

      },

participant_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"host",


"moderator",


"presenter",


"attendee",


"guest",


"bot"

        ],

      },

join_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"invited",


"lobby",


"joined",


"left",


"kicked",


"disconnected"

        ],

      },

joined_at: {
        type: DataTypes.DATE,
      
      

      },

left_at: {
        type: DataTypes.DATE,
      
      

      },

is_muted: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

is_video_enabled: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

is_screen_sharing: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

network_score: {
        type: DataTypes.INTEGER,
      
      

      },

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

  participants.associate = (db) => {


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



















































    db.participants.hasMany(db.quality_reports, {
      as: 'quality_reports_participant',
      foreignKey: {
          name: 'participantId',
      },
      constraints: false,
    });





//end loop



    db.participants.belongsTo(db.conferences, {
      as: 'conference',
      foreignKey: {
        name: 'conferenceId',
      },
      constraints: false,
    });

    db.participants.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

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




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

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



  return participants;
};


