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

name: {
        type: DataTypes.TEXT,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

submission_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"file",


"url",


"mixed"

        ],

      },

expected_deliverable: {
        type: DataTypes.TEXT,
      
      

      },

max_files: {
        type: DataTypes.INTEGER,
      
      

      },

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

  build_tasks.associate = (db) => {


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





















    db.build_tasks.hasMany(db.task_submissions, {
      as: 'task_submissions_build_task',
      foreignKey: {
          name: 'build_taskId',
      },
      constraints: false,
    });













//end loop



    db.build_tasks.belongsTo(db.lessons, {
      as: 'lesson',
      foreignKey: {
        name: 'lessonId',
      },
      constraints: false,
    });

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




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

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



  return build_tasks;
};


