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

from_node_key: {
        type: DataTypes.TEXT,
      
      

      },

to_node_key: {
        type: DataTypes.TEXT,
      
      

      },

relation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"supports",


"causes",


"enables",


"depends_on",


"contradicts",


"validates",


"mitigates",


"implements",


"precedes",


"related_to"

        ],

      },

reasoning: {
        type: DataTypes.TEXT,
      
      

      },

strength: {
        type: DataTypes.ENUM,
      
      

        values: [

"weak",


"medium",


"strong"

        ],

      },

ai_generated: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  map_edges.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.map_edges.belongsTo(db.mind_maps, {
      as: 'mind_map',
      foreignKey: {
        name: 'mind_mapId',
      },
      constraints: false,
    });

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




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

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



  return map_edges;
};


