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

joined_at: {
        type: DataTypes.DATE,
      
      

      },

membership_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"active",


"removed",


"blocked"

        ],

      },

join_method: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  classroom_memberships.associate = (db) => {


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































//end loop



    db.classroom_memberships.belongsTo(db.classrooms, {
      as: 'classroom',
      foreignKey: {
        name: 'classroomId',
      },
      constraints: false,
    });

    db.classroom_memberships.belongsTo(db.users, {
      as: 'student',
      foreignKey: {
        name: 'studentId',
      },
      constraints: false,
    });

    db.classroom_memberships.belongsTo(db.schools, {
      as: 'schools',
      foreignKey: {
        name: 'schoolsId',
      },
      constraints: false,
    });




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

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



  return classroom_memberships;
};


