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

graded_at: {
        type: DataTypes.DATE,
      
      

      },

total_score: {
        type: DataTypes.DECIMAL,
      
      

      },

max_score_snapshot: {
        type: DataTypes.DECIMAL,
      
      

      },

grade_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_graded",


"in_review",


"graded",


"reopened"

        ],

      },

teacher_feedback: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

returned_at: {
        type: DataTypes.DATE,
      
      

      },

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

  submission_grades.associate = (db) => {


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
















    db.submission_grades.hasMany(db.rubric_scores, {
      as: 'rubric_scores_submission_grade',
      foreignKey: {
          name: 'submission_gradeId',
      },
      constraints: false,
    });
















//end loop



    db.submission_grades.belongsTo(db.homework_submissions, {
      as: 'submission',
      foreignKey: {
        name: 'submissionId',
      },
      constraints: false,
    });

    db.submission_grades.belongsTo(db.users, {
      as: 'graded_by_teacher',
      foreignKey: {
        name: 'graded_by_teacherId',
      },
      constraints: false,
    });

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




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

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



  return submission_grades;
};


