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

title: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"open",


"closed",


"archived"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

last_message_at: {
        type: DataTypes.DATE,
      
      

      },

topic_tags: {
        type: DataTypes.TEXT,
      
      

      },

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

  mentor_conversations.associate = (db) => {


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




















    db.mentor_conversations.hasMany(db.mentor_messages, {
      as: 'mentor_messages_conversation',
      foreignKey: {
          name: 'conversationId',
      },
      constraints: false,
    });













//end loop



    db.mentor_conversations.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.mentor_conversations.belongsTo(db.ai_mentor_profiles, {
      as: 'mentor_profile',
      foreignKey: {
        name: 'mentor_profileId',
      },
      constraints: false,
    });

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




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

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



  return mentor_conversations;
};


