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

column_name: {
        type: DataTypes.TEXT,
      
      

      },

column_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"homework",


"quiz",


"exam",


"project",


"attendance",


"custom"

        ],

      },

max_score: {
        type: DataTypes.DECIMAL,
      
      

      },

weight: {
        type: DataTypes.DECIMAL,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

  gradebook_columns.associate = (db) => {


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



















    db.gradebook_columns.hasMany(db.gradebook_entries, {
      as: 'gradebook_entries_gradebook_column',
      foreignKey: {
          name: 'gradebook_columnId',
      },
      constraints: false,
    });













//end loop



    db.gradebook_columns.belongsTo(db.gradebooks, {
      as: 'gradebook',
      foreignKey: {
        name: 'gradebookId',
      },
      constraints: false,
    });

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

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




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

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



  return gradebook_columns;
};


