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

run_at: {
        type: DataTypes.DATE,
      
      

      },

result_count: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  screener_runs.associate = (db) => {


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
























    db.screener_runs.hasMany(db.screener_results, {
      as: 'screener_results_screener_run',
      foreignKey: {
          name: 'screener_runId',
      },
      constraints: false,
    });














//end loop



    db.screener_runs.belongsTo(db.screener_filters, {
      as: 'screener_filter',
      foreignKey: {
        name: 'screener_filterId',
      },
      constraints: false,
    });




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

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



  return screener_runs;
};


