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

student_number: {
        type: DataTypes.TEXT,
      
      

      },

gender: {
        type: DataTypes.ENUM,
      
      

        values: [

"female",


"male",


"non_binary",


"prefer_not_to_say"

        ],

      },

date_of_birth: {
        type: DataTypes.DATE,
      
      

      },

medical_notes: {
        type: DataTypes.TEXT,
      
      

      },

enrollment_date: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"inactive",


"graduated",


"transferred"

        ],

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  students.associate = (db) => {


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














    db.students.hasMany(db.student_parent_links, {
      as: 'student_parent_links_student',
      foreignKey: {
          name: 'studentId',
      },
      constraints: false,
    });




    db.students.hasMany(db.class_enrollments, {
      as: 'class_enrollments_student',
      foreignKey: {
          name: 'studentId',
      },
      constraints: false,
    });





    db.students.hasMany(db.attendance_records, {
      as: 'attendance_records_student',
      foreignKey: {
          name: 'studentId',
      },
      constraints: false,
    });



    db.students.hasMany(db.submissions, {
      as: 'submissions_student',
      foreignKey: {
          name: 'studentId',
      },
      constraints: false,
    });



    db.students.hasMany(db.grade_records, {
      as: 'grade_records_student',
      foreignKey: {
          name: 'studentId',
      },
      constraints: false,
    });







//end loop



    db.students.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.students.belongsTo(db.schools, {
      as: 'school',
      foreignKey: {
        name: 'schoolId',
      },
      constraints: false,
    });

    db.students.belongsTo(db.campuses, {
      as: 'campus',
      foreignKey: {
        name: 'campusId',
      },
      constraints: false,
    });




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

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



  return students;
};


