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

title: {
        type: DataTypes.TEXT,
      
      

      },

thread_scope: {
        type: DataTypes.ENUM,
      
      

        values: [

"general",


"matter"

        ],

      },

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

      },

last_activity_at: {
        type: DataTypes.DATE,
      
      

      },

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

  assistant_threads.associate = (db) => {


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












    db.assistant_threads.hasMany(db.assistant_messages, {
      as: 'assistant_messages_thread',
      foreignKey: {
          name: 'threadId',
      },
      constraints: false,
    });




















//end loop



    db.assistant_threads.belongsTo(db.users, {
      as: 'owner',
      foreignKey: {
        name: 'ownerId',
      },
      constraints: false,
    });

    db.assistant_threads.belongsTo(db.matters, {
      as: 'matter',
      foreignKey: {
        name: 'matterId',
      },
      constraints: false,
    });




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

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



  return assistant_threads;
};


