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

score: {
        type: DataTypes.DECIMAL,
      
      

      },

entry_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"normal",


"excused",


"missing",


"incomplete"

        ],

      },

recorded_at: {
        type: DataTypes.DATE,
      
      

      },

remarks: {
        type: DataTypes.TEXT,
      
      

      },

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

  gradebook_entries.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.gradebook_entries.belongsTo(db.gradebook_columns, {
      as: 'gradebook_column',
      foreignKey: {
        name: 'gradebook_columnId',
      },
      constraints: false,
    });

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

    db.gradebook_entries.belongsTo(db.users, {
      as: 'recorded_by',
      foreignKey: {
        name: 'recorded_byId',
      },
      constraints: false,
    });

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




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

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



  return gradebook_entries;
};


