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

coach_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"career_coach",


"learning_coach",


"tutor"

        ],

      },

session_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"initiated",


"in_progress",


"completed",


"archived"

        ],

      },

topic: {
        type: DataTypes.TEXT,
      
      

      },

private_notes: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

ended_at: {
        type: DataTypes.DATE,
      
      

      },

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

  coaching_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.coaching_sessions.hasMany(db.messages, {
      as: 'messages_coaching_session',
      foreignKey: {
          name: 'coaching_sessionId',
      },
      constraints: false,
    });






//end loop



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




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

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



  return coaching_sessions;
};


