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

title: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

max_points: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  test_sections.associate = (db) => {


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
















    db.test_sections.hasMany(db.test_items, {
      as: 'test_items_section',
      foreignKey: {
          name: 'sectionId',
      },
      constraints: false,
    });













//end loop



    db.test_sections.belongsTo(db.tests, {
      as: 'test',
      foreignKey: {
        name: 'testId',
      },
      constraints: false,
    });




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

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



  return test_sections;
};


