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

assignment_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"subject_teacher",


"adviser"

        ],

      },

assigned_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  teaching_assignments.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.teaching_assignments.belongsTo(db.users, {
      as: 'teacher',
      foreignKey: {
        name: 'teacherId',
      },
      constraints: false,
    });

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

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

    db.teaching_assignments.belongsTo(db.users, {
      as: 'assigned_by',
      foreignKey: {
        name: 'assigned_byId',
      },
      constraints: false,
    });

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




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

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



  return teaching_assignments;
};


