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

reported_at: {
        type: DataTypes.DATE,
      
      

      },

packet_loss_percent: {
        type: DataTypes.DECIMAL,
      
      

      },

rtt_ms: {
        type: DataTypes.INTEGER,
      
      

      },

jitter_ms: {
        type: DataTypes.DECIMAL,
      
      

      },

send_bitrate_kbps: {
        type: DataTypes.DECIMAL,
      
      

      },

recv_bitrate_kbps: {
        type: DataTypes.DECIMAL,
      
      

      },

media_quality: {
        type: DataTypes.ENUM,
      
      

        values: [

"excellent",


"good",


"fair",


"poor",


"bad"

        ],

      },

raw_stats: {
        type: DataTypes.TEXT,
      
      

      },

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

  quality_reports.associate = (db) => {


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























































//end loop



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

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

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




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

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



  return quality_reports;
};


