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

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed",


"cancelled"

        ],

      },

iterations: {
        type: DataTypes.INTEGER,
      
      

      },

inputs_json: {
        type: DataTypes.TEXT,
      
      

      },

results_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  monte_carlo_runs.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.monte_carlo_runs.belongsTo(db.economic_models, {
      as: 'economic_model',
      foreignKey: {
        name: 'economic_modelId',
      },
      constraints: false,
    });

    db.monte_carlo_runs.belongsTo(db.users, {
      as: 'triggered_by',
      foreignKey: {
        name: 'triggered_byId',
      },
      constraints: false,
    });

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




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

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



  return monte_carlo_runs;
};


