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

invite_email: {
        type: DataTypes.TEXT,
      
      

      },

invite_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"org_admin",


"coordinator",


"partner",


"customer"

        ],

      },

invite_token: {
        type: DataTypes.TEXT,
      
      

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

accepted_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"accepted",


"expired",


"revoked"

        ],

      },

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

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




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

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



  return organization_invitations;
};


