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

extension_scope: {
        type: DataTypes.ENUM,
      
      

        values: [

"all_students",


"selected_students"

        ],

      },

extended_due_at: {
        type: DataTypes.DATE,
      
      

      },

extended_late_until_at: {
        type: DataTypes.DATE,
      
      

      },

reason: {
        type: DataTypes.TEXT,
      
      

      },

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

  homework_extensions.associate = (db) => {

    db.homework_extensions.belongsToMany(db.users, {
      as: 'students',
      foreignKey: {
        name: 'homework_extensions_studentsId',
      },
      constraints: false,
      through: 'homework_extensionsStudentsUsers',
    });

    db.homework_extensions.belongsToMany(db.users, {
      as: 'students_filter',
      foreignKey: {
        name: 'homework_extensions_studentsId',
      },
      constraints: false,
      through: 'homework_extensionsStudentsUsers',
    });


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































//end loop



    db.homework_extensions.belongsTo(db.homeworks, {
      as: 'homework',
      foreignKey: {
        name: 'homeworkId',
      },
      constraints: false,
    });

    db.homework_extensions.belongsTo(db.users, {
      as: 'created_by_user',
      foreignKey: {
        name: 'created_by_userId',
      },
      constraints: false,
    });

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




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

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



  return homework_extensions;
};


