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

first_name: {
        type: DataTypes.TEXT,
      
      

      },

last_name: {
        type: DataTypes.TEXT,
      
      

      },

date_of_birth: {
        type: DataTypes.DATE,
      
      

      },

grade_level: {
        type: DataTypes.INTEGER,
      
      

      },

gender: {
        type: DataTypes.ENUM,
      
      

        values: [

"female",


"male",


"nonbinary",


"prefer_not_to_say"

        ],

      },

allergies: {
        type: DataTypes.TEXT,
      
      

      },

medical_notes: {
        type: DataTypes.TEXT,
      
      

      },

special_needs_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  campers.associate = (db) => {


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













    db.campers.hasMany(db.enrollments, {
      as: 'enrollments_camper',
      foreignKey: {
          name: 'camperId',
      },
      constraints: false,
    });
















//end loop



    db.campers.belongsTo(db.guardians, {
      as: 'primary_guardian',
      foreignKey: {
        name: 'primary_guardianId',
      },
      constraints: false,
    });



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


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

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



  return campers;
};


