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

document_title: {
        type: DataTypes.TEXT,
      
      

      },

ingestion_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"processing",


"completed",


"failed",


"needs_review"

        ],

      },

language: {
        type: DataTypes.TEXT,
      
      

      },

published_at: {
        type: DataTypes.DATE,
      
      

      },

ingested_at: {
        type: DataTypes.DATE,
      
      

      },

document_summary: {
        type: DataTypes.TEXT,
      
      

      },

tags_csv: {
        type: DataTypes.TEXT,
      
      

      },

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

  knowledge_documents.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_documents.hasMany(db.knowledge_chunks, {
      as: 'knowledge_chunks_knowledge_document',
      foreignKey: {
          name: 'knowledge_documentId',
      },
      constraints: false,
    });



















//end loop



    db.knowledge_documents.belongsTo(db.knowledge_sources, {
      as: 'knowledge_source',
      foreignKey: {
        name: 'knowledge_sourceId',
      },
      constraints: false,
    });




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

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



  return knowledge_documents;
};


