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,
      },

attendance_date: {
        type: DataTypes.DATE,
      
      

      },

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

    db.attendance_sessions.belongsTo(db.users, {
      as: 'recorded_by',
      foreignKey: {
        name: 'recorded_byId',
      },
      constraints: false,
    });

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




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

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



  return attendance_sessions;
};


