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

chunk_index: {
        type: DataTypes.INTEGER,
      
      

      },

chunk_text: {
        type: DataTypes.TEXT,
      
      

      },

token_count_estimate: {
        type: DataTypes.DECIMAL,
      
      

      },

embedding_provider: {
        type: DataTypes.TEXT,
      
      

      },

embedding_model: {
        type: DataTypes.TEXT,
      
      

      },

chunk_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"table",


"code",


"caption"

        ],

      },

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

  source_chunks.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.source_chunks.belongsTo(db.sources, {
      as: 'source',
      foreignKey: {
        name: 'sourceId',
      },
      constraints: false,
    });

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




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

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



  return source_chunks;
};


