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

name: {
        type: DataTypes.TEXT,
      
      

      },

lab_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"attack_simulation",


"digital_twin",


"ai_hacker_simulator"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"available",


"running",


"maintenance",


"offline"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

created_on: {
        type: DataTypes.DATE,
      
      

      },

max_duration_minutes: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  simulation_labs.associate = (db) => {


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






















    db.simulation_labs.hasMany(db.simulation_runs, {
      as: 'simulation_runs_lab',
      foreignKey: {
          name: 'labId',
      },
      constraints: false,
    });







//end loop



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




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

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



  return simulation_labs;
};


