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

node_name: {
        type: DataTypes.TEXT,
      
      

      },

node_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"topic",


"framework",


"offer",


"hook",


"audience_segment",


"policy",


"constraint",


"metric",


"competitor",


"custom"

        ],

      },

node_description: {
        type: DataTypes.TEXT,
      
      

      },

importance_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  knowledge_nodes.associate = (db) => {

    db.knowledge_nodes.belongsToMany(db.knowledge_chunks, {
      as: 'supporting_chunks',
      foreignKey: {
        name: 'knowledge_nodes_supporting_chunksId',
      },
      constraints: false,
      through: 'knowledge_nodesSupporting_chunksKnowledge_chunks',
    });

    db.knowledge_nodes.belongsToMany(db.knowledge_chunks, {
      as: 'supporting_chunks_filter',
      foreignKey: {
        name: 'knowledge_nodes_supporting_chunksId',
      },
      constraints: false,
      through: 'knowledge_nodesSupporting_chunksKnowledge_chunks',
    });


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






























//end loop






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

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



  return knowledge_nodes;
};


