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

invite_token: {
        type: DataTypes.TEXT,
      
      

      },

sent_at: {
        type: DataTypes.DATE,
      
      

      },

viewed_at: {
        type: DataTypes.DATE,
      
      

      },

accepted_at: {
        type: DataTypes.DATE,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

send_count: {
        type: DataTypes.INTEGER,
      
      

      },

channel: {
        type: DataTypes.ENUM,
      
      

        values: [

"email",


"sms",


"whatsapp"

        ],

      },

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

  participant_invitations.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.participant_invitations.belongsTo(db.contract_participants, {
      as: 'contract_participant',
      foreignKey: {
        name: 'contract_participantId',
      },
      constraints: false,
    });

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




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

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



  return participant_invitations;
};


