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

grade_name: {
        type: DataTypes.TEXT,
      
      

      },

grade_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  grade_levels.associate = (db) => {


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







    db.grade_levels.hasMany(db.subjects, {
      as: 'subjects_grade_level',
      foreignKey: {
          name: 'grade_levelId',
      },
      constraints: false,
    });


    db.grade_levels.hasMany(db.classrooms, {
      as: 'classrooms_grade_level',
      foreignKey: {
          name: 'grade_levelId',
      },
      constraints: false,
    });
























//end loop



    db.grade_levels.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });




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

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



  return grade_levels;
};


