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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"webrtc",


"twilio"

        ],

      },

provider_room_name: {
        type: DataTypes.TEXT,
      
      

      },

provider_session_reference: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

call_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"initiated",


"ringing",


"connected",


"ended",


"failed"

        ],

      },

call_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  video_calls.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.video_calls.belongsTo(db.consultations, {
      as: 'consultation',
      foreignKey: {
        name: 'consultationId',
      },
      constraints: false,
    });

    db.video_calls.belongsTo(db.chat_sessions, {
      as: 'chat_session',
      foreignKey: {
        name: 'chat_sessionId',
      },
      constraints: false,
    });

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




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

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



  return video_calls;
};


