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

call_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"voice",


"video"

        ],

      },

call_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"initiated",


"ringing",


"ongoing",


"ended",


"missed",


"declined"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

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

  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.calls.belongsTo(db.conversations, {
      as: 'conversation',
      foreignKey: {
        name: 'conversationId',
      },
      constraints: false,
    });

    db.calls.belongsTo(db.users, {
      as: 'initiator',
      foreignKey: {
        name: 'initiatorId',
      },
      constraints: false,
    });




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

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



  return calls;
};


