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

name: {
        type: DataTypes.TEXT,
      
      

      },

min_grade: {
        type: DataTypes.INTEGER,
      
      

      },

max_grade: {
        type: DataTypes.INTEGER,
      
      

      },

theme_scripture_reference: {
        type: DataTypes.TEXT,
      
      

      },

theme_scripture_text: {
        type: DataTypes.TEXT,
      
      

      },

focus_summary: {
        type: DataTypes.TEXT,
      
      

      },

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

  age_groups.associate = (db) => {


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













    db.age_groups.hasMany(db.enrollments, {
      as: 'enrollments_age_group',
      foreignKey: {
          name: 'age_groupId',
      },
      constraints: false,
    });






    db.age_groups.hasMany(db.field_trip_events, {
      as: 'field_trip_events_age_group',
      foreignKey: {
          name: 'age_groupId',
      },
      constraints: false,
    });






    db.age_groups.hasMany(db.activity_blocks, {
      as: 'activity_blocks_age_group',
      foreignKey: {
          name: 'age_groupId',
      },
      constraints: false,
    });



    db.age_groups.hasMany(db.staff_assignments, {
      as: 'staff_assignments_age_group',
      foreignKey: {
          name: 'age_groupId',
      },
      constraints: false,
    });




//end loop






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

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



  return age_groups;
};


