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

entry_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"grade_9_entry",


"transfer"

        ],

      },

applicant_full_name: {
        type: DataTypes.TEXT,
      
      

      },

gender: {
        type: DataTypes.ENUM,
      
      

        values: [

"female",


"male"

        ],

      },

date_of_birth: {
        type: DataTypes.DATE,
      
      

      },

previous_school: {
        type: DataTypes.TEXT,
      
      

      },

guardian_full_name: {
        type: DataTypes.TEXT,
      
      

      },

guardian_phone: {
        type: DataTypes.TEXT,
      
      

      },

guardian_email: {
        type: DataTypes.TEXT,
      
      

      },

address_text: {
        type: DataTypes.TEXT,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"submitted",


"under_review",


"accepted",


"rejected",


"waitlisted"

        ],

      },

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

  admission_applications.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.admission_applications.belongsTo(db.grades, {
      as: 'requested_grade',
      foreignKey: {
        name: 'requested_gradeId',
      },
      constraints: false,
    });

    db.admission_applications.belongsTo(db.streams, {
      as: 'requested_stream',
      foreignKey: {
        name: 'requested_streamId',
      },
      constraints: false,
    });



    db.admission_applications.hasMany(db.file, {
      as: 'documents',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.admission_applications.getTableName(),
        belongsToColumn: 'documents',
      },
    });


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

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



  return admission_applications;
};


