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

simulation_title: {
        type: DataTypes.TEXT,
      
      

      },

simulation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"role_play",


"scenario",


"call_flow"

        ],

      },

scenario_context: {
        type: DataTypes.TEXT,
      
      

      },

success_criteria: {
        type: DataTypes.TEXT,
      
      

      },

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

  simulations.associate = (db) => {


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























    db.simulations.hasMany(db.simulation_steps, {
      as: 'simulation_steps_simulation',
      foreignKey: {
          name: 'simulationId',
      },
      constraints: false,
    });

























//end loop



    db.simulations.belongsTo(db.missions, {
      as: 'mission',
      foreignKey: {
        name: 'missionId',
      },
      constraints: false,
    });

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




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

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



  return simulations;
};


