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

day_of_week: {
        type: DataTypes.ENUM,
      
      

        values: [

"monday",


"tuesday",


"wednesday",


"thursday",


"friday",


"saturday",


"sunday"

        ],

      },

starts_at: {
        type: DataTypes.DATE,
      
      

      },

ends_at: {
        type: DataTypes.DATE,
      
      

      },

room: {
        type: DataTypes.TEXT,
      
      

      },

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

  timetable_periods.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_periods.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.timetable_periods.belongsTo(db.timetables, {
      as: 'timetable',
      foreignKey: {
        name: 'timetableId',
      },
      constraints: false,
    });

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




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

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



  return timetable_periods;
};


