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

submission_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"not_submitted",


"submitted",


"resubmitted",


"graded",


"returned"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

student_note: {
        type: DataTypes.TEXT,
      
      

      },

score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

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

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

    db.submissions.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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


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

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



  return submissions;
};


