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

day_of_week: {
        type: DataTypes.ENUM,
      
      

        values: [

"senin",


"selasa",


"rabu",


"kamis",


"jumat",


"sabtu"

        ],

      },

period_number: {
        type: DataTypes.INTEGER,
      
      

      },

start_time: {
        type: DataTypes.TEXT,
      
      

      },

end_time: {
        type: DataTypes.TEXT,
      
      

      },

room: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  timetable_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.timetable_entries.belongsTo(db.classes, {
      as: 'class',
      foreignKey: {
        name: 'classId',
      },
      constraints: false,
    });

    db.timetable_entries.belongsTo(db.class_subjects, {
      as: 'class_subject',
      foreignKey: {
        name: 'class_subjectId',
      },
      constraints: false,
    });

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




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

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



  return timetable_entries;
};


