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

item_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"decision",


"action_item",


"fact",


"risk",


"question",


"answer",


"follow_up"

        ],

      },

title: {
        type: DataTypes.TEXT,
      
      

      },

details: {
        type: DataTypes.TEXT,
      
      

      },

importance: {
        type: DataTypes.ENUM,
      
      

        values: [

"low",


"medium",


"high",


"critical"

        ],

      },

item_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"in_progress",


"done",


"dismissed"

        ],

      },

captured_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

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

  knowledge_graph_items.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_graph_items.hasMany(db.tasks, {
      as: 'tasks_knowledge_graph_item',
      foreignKey: {
          name: 'knowledge_graph_itemId',
      },
      constraints: false,
    });




















//end loop



    db.knowledge_graph_items.belongsTo(db.ai_companion_sessions, {
      as: 'ai_companion_session',
      foreignKey: {
        name: 'ai_companion_sessionId',
      },
      constraints: false,
    });

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




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

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



  return knowledge_graph_items;
};


