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

criterion_title: {
        type: DataTypes.TEXT,
      
      

      },

criterion_description: {
        type: DataTypes.TEXT,
      
      

      },

criterion_max_score: {
        type: DataTypes.DECIMAL,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  homework_rubrics.associate = (db) => {


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
















    db.homework_rubrics.hasMany(db.rubric_scores, {
      as: 'rubric_scores_rubric_item',
      foreignKey: {
          name: 'rubric_itemId',
      },
      constraints: false,
    });
















//end loop



    db.homework_rubrics.belongsTo(db.homeworks, {
      as: 'homework',
      foreignKey: {
        name: 'homeworkId',
      },
      constraints: false,
    });

    db.homework_rubrics.belongsTo(db.schools, {
      as: 'schools',
      foreignKey: {
        name: 'schoolsId',
      },
      constraints: false,
    });




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

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



  return homework_rubrics;
};


