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

sample_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"terminated_user",


"onboarded_user",


"privileged_admin",


"reviewed_user",


"service_account",


"exception_case"

        ],

      },

display_name: {
        type: DataTypes.TEXT,
      
      

      },

identifier: {
        type: DataTypes.TEXT,
      
      

      },

department: {
        type: DataTypes.TEXT,
      
      

      },

role_name: {
        type: DataTypes.TEXT,
      
      

      },

manager: {
        type: DataTypes.TEXT,
      
      

      },

event_date: {
        type: DataTypes.DATE,
      
      

      },

risk_tier: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"new",


"in_progress",


"packet_ready",


"closed",


"archived"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  sampled_subjects.associate = (db) => {


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














    db.sampled_subjects.hasMany(db.proof_packets, {
      as: 'proof_packets_sampled_subject',
      foreignKey: {
          name: 'sampled_subjectId',
      },
      constraints: false,
    });












//end loop



    db.sampled_subjects.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.sampled_subjects.belongsTo(db.identity_workflows, {
      as: 'workflow',
      foreignKey: {
        name: 'workflowId',
      },
      constraints: false,
    });




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

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



  return sampled_subjects;
};


