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

score: {
        type: DataTypes.DECIMAL,
      
      

      },

out_of: {
        type: DataTypes.DECIMAL,
      
      

      },

result_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"published"

        ],

      },

entered_at: {
        type: DataTypes.DATE,
      
      

      },

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

  exam_results.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.exam_results.belongsTo(db.exams, {
      as: 'exam',
      foreignKey: {
        name: 'examId',
      },
      constraints: false,
    });

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

    db.exam_results.belongsTo(db.subjects, {
      as: 'subject',
      foreignKey: {
        name: 'subjectId',
      },
      constraints: false,
    });

    db.exam_results.belongsTo(db.staff_members, {
      as: 'entered_by',
      foreignKey: {
        name: 'entered_byId',
      },
      constraints: false,
    });




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

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



  return exam_results;
};


