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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_started",


"in_progress",


"passed",


"failed",


"expired"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

attempt_count: {
        type: DataTypes.INTEGER,
      
      

      },

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

  authentication_sessions.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity




























    db.authentication_sessions.hasMany(db.authentication_attempts, {
      as: 'authentication_attempts_authentication_session',
      foreignKey: {
          name: 'authentication_sessionId',
      },
      constraints: false,
    });

















//end loop



    db.authentication_sessions.belongsTo(db.contract_participants, {
      as: 'contract_participant',
      foreignKey: {
        name: 'contract_participantId',
      },
      constraints: false,
    });

    db.authentication_sessions.belongsTo(db.service_auth_policies, {
      as: 'service_auth_policy',
      foreignKey: {
        name: 'service_auth_policyId',
      },
      constraints: false,
    });

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




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

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



  return authentication_sessions;
};


