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

asked_at: {
        type: DataTypes.DATE,
      
      

      },

user_prompt: {
        type: DataTypes.TEXT,
      
      

      },

ai_response: {
        type: DataTypes.TEXT,
      
      

      },

model_name: {
        type: DataTypes.TEXT,
      
      

      },

confidence_score: {
        type: DataTypes.DECIMAL,
      
      

      },

triage_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"self_care",


"routine",


"urgent",


"emergency"

        ],

      },

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

      },

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

  chatbot_interactions.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.chatbot_interactions.belongsTo(db.patient_profiles, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.chatbot_interactions.belongsTo(db.chat_sessions, {
      as: 'chat_session',
      foreignKey: {
        name: 'chat_sessionId',
      },
      constraints: false,
    });

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




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

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



  return chatbot_interactions;
};


