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

event_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"STATUS_CHANGED",


"MATCH_SENT",


"MATCH_VIEWED",


"MATCH_RESPONDED",


"MATCH_DECLINED",


"MATCH_SCHEDULED",


"MATCH_COMPLETED",


"NOTE_ADDED"

        ],

      },

from_value: {
        type: DataTypes.TEXT,
      
      

      },

to_value: {
        type: DataTypes.TEXT,
      
      

      },

meta_json: {
        type: DataTypes.TEXT,
      
      

      },

created_at_ts: {
        type: DataTypes.DATE,
      
      

      },

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

  lead_events.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.lead_events.belongsTo(db.leads, {
      as: 'lead',
      foreignKey: {
        name: 'leadId',
      },
      constraints: false,
    });

    db.lead_events.belongsTo(db.users, {
      as: 'actor_user',
      foreignKey: {
        name: 'actor_userId',
      },
      constraints: false,
    });




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

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



  return lead_events;
};


