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

match_score: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"SENT",


"VIEWED",


"RESPONDED",


"DECLINED",


"SCHEDULED",


"COMPLETED"

        ],

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

viewed_at: {
        type: DataTypes.DATE,
      
      

      },

responded_at: {
        type: DataTypes.DATE,
      
      

      },

scheduled_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

declined_at: {
        type: DataTypes.DATE,
      
      

      },

created_at_ts: {
        type: DataTypes.DATE,
      
      

      },

updated_at_ts: {
        type: DataTypes.DATE,
      
      

      },

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

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

    db.lead_matches.belongsTo(db.businesses, {
      as: 'business',
      foreignKey: {
        name: 'businessId',
      },
      constraints: false,
    });




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

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



  return lead_matches;
};


