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

title: {
        type: DataTypes.TEXT,
      
      

      },

tutor_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"socratic",


"explain_like_im_5",


"exam_prep",


"study_plan",


"debugging",


"general"

        ],

      },

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

      },

last_message_at: {
        type: DataTypes.DATE,
      
      

      },

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

  tutor_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.tutor_conversations.hasMany(db.tutor_messages, {
      as: 'tutor_messages_conversation',
      foreignKey: {
          name: 'conversationId',
      },
      constraints: false,
    });






//end loop



    db.tutor_conversations.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

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

    db.tutor_conversations.belongsTo(db.subjects, {
      as: 'subject',
      foreignKey: {
        name: 'subjectId',
      },
      constraints: false,
    });

    db.tutor_conversations.belongsTo(db.topics, {
      as: 'topic',
      foreignKey: {
        name: 'topicId',
      },
      constraints: false,
    });

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




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

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



  return tutor_conversations;
};


