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

session_at: {
        type: DataTypes.DATE,
      
      

      },

session_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"period",


"exam",


"homeroom"

        ],

      },

note: {
        type: DataTypes.TEXT,
      
      

      },

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

  attendance_sessions.associate = (db) => {


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

























    db.attendance_sessions.hasMany(db.attendance_records, {
      as: 'attendance_records_attendance_session',
      foreignKey: {
          name: 'attendance_sessionId',
      },
      constraints: false,
    });














//end loop



    db.attendance_sessions.belongsTo(db.class_sections, {
      as: 'class_section',
      foreignKey: {
        name: 'class_sectionId',
      },
      constraints: false,
    });

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

    db.attendance_sessions.belongsTo(db.staff_members, {
      as: 'teacher',
      foreignKey: {
        name: 'teacherId',
      },
      constraints: false,
    });




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

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



  return attendance_sessions;
};


