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

level: {
        type: DataTypes.ENUM,
      
      

        values: [

"sd",


"smp",


"sma",


"smk"

        ],

      },

name: {
        type: DataTypes.TEXT,
      
      

      },

grade_start: {
        type: DataTypes.INTEGER,
      
      

      },

grade_end: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  education_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.education_levels.hasMany(db.classes, {
      as: 'classes_education_level',
      foreignKey: {
          name: 'education_levelId',
      },
      constraints: false,
    });


















    db.education_levels.hasMany(db.fee_definitions, {
      as: 'fee_definitions_education_level',
      foreignKey: {
          name: 'education_levelId',
      },
      constraints: false,
    });






//end loop



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




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

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



  return education_levels;
};


