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

score: {
        type: DataTypes.DECIMAL,
      
      

      },

letter_grade: {
        type: DataTypes.ENUM,
      
      

        values: [

"A",


"B",


"C",


"D",


"F",


"I"

        ],

      },

graded_at: {
        type: DataTypes.DATE,
      
      

      },

comment: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  grade_records.associate = (db) => {


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































//end loop



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

    db.grade_records.belongsTo(db.students, {
      as: 'student',
      foreignKey: {
        name: 'studentId',
      },
      constraints: false,
    });




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

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



  return grade_records;
};


