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

name: {
        type: DataTypes.TEXT,
      
      

      },

category: {
        type: DataTypes.ENUM,
      
      

        values: [

"homework",


"quiz",


"test",


"project",


"participation",


"other"

        ],

      },

weight: {
        type: DataTypes.DECIMAL,
      
      

      },

max_points: {
        type: DataTypes.INTEGER,
      
      

      },

assigned_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

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

      },

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

  grade_items.associate = (db) => {


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

























    db.grade_items.hasMany(db.grade_records, {
      as: 'grade_records_grade_item',
      foreignKey: {
          name: 'grade_itemId',
      },
      constraints: false,
    });







//end loop



    db.grade_items.belongsTo(db.course_sections, {
      as: 'course_section',
      foreignKey: {
        name: 'course_sectionId',
      },
      constraints: false,
    });

    db.grade_items.belongsTo(db.teachers, {
      as: 'teacher',
      foreignKey: {
        name: 'teacherId',
      },
      constraints: false,
    });




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

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



  return grade_items;
};


