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: [

"monday",


"tuesday",


"wednesday",


"thursday",


"friday",


"saturday",


"sunday"

        ],

      },

start_time: {
        type: DataTypes.DATE,
      
      

      },

end_time: {
        type: DataTypes.DATE,
      
      

      },

effective_from: {
        type: DataTypes.DATE,
      
      

      },

effective_to: {
        type: DataTypes.DATE,
      
      

      },

repeat_pattern: {
        type: DataTypes.ENUM,
      
      

        values: [

"weekly",


"biweekly",


"once"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

      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.course_sections, {
      as: 'course_section',
      foreignKey: {
        name: 'course_sectionId',
      },
      constraints: false,
    });

    db.timetable_entries.belongsTo(db.rooms, {
      as: 'room',
      foreignKey: {
        name: 'roomId',
      },
      constraints: false,
    });




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

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



  return timetable_entries;
};


