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

session_key_id: {
        type: DataTypes.TEXT,
      
      

      },

algorithm: {
        type: DataTypes.ENUM,
      
      

        values: [

"rsa",


"ecdh",


"aes_gcm",


"xchacha20_poly1305"

        ],

      },

key_length_bits: {
        type: DataTypes.INTEGER,
      
      

      },

valid_from: {
        type: DataTypes.DATE,
      
      

      },

valid_until: {
        type: DataTypes.DATE,
      
      

      },

is_discarded: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

discarded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  encryption_sessions.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.encryption_sessions.belongsTo(db.chats, {
      as: 'chat',
      foreignKey: {
        name: 'chatId',
      },
      constraints: false,
    });

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




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

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



  return encryption_sessions;
};


