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

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"belum",


"sudah",


"terlambat"

        ],

      },

answer_text: {
        type: DataTypes.TEXT,
      
      

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

teacher_feedback: {
        type: DataTypes.TEXT,
      
      

      },

graded_at: {
        type: DataTypes.DATE,
      
      

      },

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

  assignment_submissions.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.assignment_submissions.belongsTo(db.assignments, {
      as: 'assignment',
      foreignKey: {
        name: 'assignmentId',
      },
      constraints: false,
    });

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

    db.assignment_submissions.belongsTo(db.users, {
      as: 'graded_by',
      foreignKey: {
        name: 'graded_byId',
      },
      constraints: false,
    });

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



    db.assignment_submissions.hasMany(db.file, {
      as: 'answer_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.assignment_submissions.getTableName(),
        belongsToColumn: 'answer_files',
      },
    });


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

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



  return assignment_submissions;
};


