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

name: {
        type: DataTypes.TEXT,
      
      

      },

type: {
        type: DataTypes.ENUM,
      
      

        values: [

"ulangan_harian",


"uts",


"uas",


"kenaikan_kelas",


"lainnya"

        ],

      },

active: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  exam_categories.associate = (db) => {


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




















    db.exam_categories.hasMany(db.exams, {
      as: 'exams_category',
      foreignKey: {
          name: 'categoryId',
      },
      constraints: false,
    });











//end loop



    db.exam_categories.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });




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

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



  return exam_categories;
};


