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

source_entity_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"document",


"metallurgical_test",


"sample",


"flowsheet",


"flowsheet_node",


"economic_model",


"project_phase",


"ore_body"

        ],

      },

source_entity_key: {
        type: DataTypes.TEXT,
      
      

      },

target_entity_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"document",


"metallurgical_test",


"sample",


"flowsheet",


"flowsheet_node",


"economic_model",


"project_phase",


"ore_body"

        ],

      },

target_entity_key: {
        type: DataTypes.TEXT,
      
      

      },

link_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  entity_links.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.entity_links.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return entity_links;
};


