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

invitee_email: {
        type: DataTypes.TEXT,
      
      

      },

invitee_name: {
        type: DataTypes.TEXT,
      
      

      },

role: {
        type: DataTypes.ENUM,
      
      

        values: [

"org_admin",


"compliance_manager",


"security_manager",


"iam_operator",


"auditor",


"read_only_client"

        ],

      },

invite_token_hash: {
        type: DataTypes.TEXT,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"accepted",


"revoked",


"expired"

        ],

      },

accepted_at: {
        type: DataTypes.DATE,
      
      

      },

revoked_at: {
        type: DataTypes.DATE,
      
      

      },

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

  user_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.user_invitations.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.user_invitations.belongsTo(db.users, {
      as: 'invited_by_user',
      foreignKey: {
        name: 'invited_by_userId',
      },
      constraints: false,
    });




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

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



  return user_invitations;
};


