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

name: {
        type: DataTypes.TEXT,
      
      

      },

code: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

  grades.associate = (db) => {


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













    db.grades.hasMany(db.classes, {
      as: 'classes_grade',
      foreignKey: {
          name: 'gradeId',
      },
      constraints: false,
    });








    db.grades.hasMany(db.fee_plans, {
      as: 'fee_plans_grade',
      foreignKey: {
          name: 'gradeId',
      },
      constraints: false,
    });










//end loop



    db.grades.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });




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

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



  return grades;
};


