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

invitee_email: {
        type: DataTypes.TEXT,
      
      

      },

invite_code: {
        type: DataTypes.TEXT,
      
      

      },

invite_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"moderator",


"member",


"guest"

        ],

      },

invitation_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"accepted",


"expired",


"revoked"

        ],

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

accepted_at: {
        type: DataTypes.DATE,
      
      

      },

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

  room_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.room_invitations.belongsTo(db.rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });

    db.room_invitations.belongsTo(db.users, {
      as: 'invited_by',
      foreignKey: {
        name: 'invited_byId',
      },
      constraints: false,
    });

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




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

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



  return room_invitations;
};


