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

chunk_label: {
        type: DataTypes.TEXT,
      
      

      },

chunk_text: {
        type: DataTypes.TEXT,
      
      

      },

source_locator: {
        type: DataTypes.TEXT,
      
      

      },

recency_weight: {
        type: DataTypes.DECIMAL,
      
      

      },

quality_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  knowledge_chunks.associate = (db) => {


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






















    db.knowledge_chunks.hasMany(db.output_citations, {
      as: 'output_citations_knowledge_chunk',
      foreignKey: {
          name: 'knowledge_chunkId',
      },
      constraints: false,
    });









//end loop



    db.knowledge_chunks.belongsTo(db.knowledge_documents, {
      as: 'knowledge_document',
      foreignKey: {
        name: 'knowledge_documentId',
      },
      constraints: false,
    });




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

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



  return knowledge_chunks;
};


