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

companion_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"paused",


"failed",


"ended"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

system_prompt_version: {
        type: DataTypes.TEXT,
      
      

      },

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

  ai_companion_sessions.associate = (db) => {


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


































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






















//end loop



    db.ai_companion_sessions.belongsTo(db.conferences, {
      as: 'conference',
      foreignKey: {
        name: 'conferenceId',
      },
      constraints: false,
    });

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




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

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



  return ai_companion_sessions;
};


