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,
      },

name: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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.classes, {
      as: 'classes_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;
};


