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

title: {
        type: DataTypes.TEXT,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

assigned_at: {
        type: DataTypes.DATE,
      
      

      },

due_at: {
        type: DataTypes.DATE,
      
      

      },

assignment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"closed",


"archived"

        ],

      },

max_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  assignments.associate = (db) => {


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








































    db.assignments.hasMany(db.submissions, {
      as: 'submissions_assignment',
      foreignKey: {
          name: 'assignmentId',
      },
      constraints: false,
    });
















//end loop



    db.assignments.belongsTo(db.courses, {
      as: 'course',
      foreignKey: {
        name: 'courseId',
      },
      constraints: false,
    });

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




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

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



  return assignments;
};


