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

submitted_datetime: {
        type: DataTypes.DATE,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"submitted",


"approved",


"waitlisted",


"cancelled"

        ],

      },

application_fee_waived: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  enrollments.associate = (db) => {


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














    db.enrollments.hasMany(db.payments, {
      as: 'payments_enrollment',
      foreignKey: {
          name: 'enrollmentId',
      },
      constraints: false,
    });



    db.enrollments.hasMany(db.document_signatures, {
      as: 'document_signatures_enrollment',
      foreignKey: {
          name: 'enrollmentId',
      },
      constraints: false,
    });




    db.enrollments.hasMany(db.trip_registrations, {
      as: 'trip_registrations_enrollment',
      foreignKey: {
          name: 'enrollmentId',
      },
      constraints: false,
    });




    db.enrollments.hasMany(db.end_of_summer_trip_selections, {
      as: 'end_of_summer_trip_selections_enrollment',
      foreignKey: {
          name: 'enrollmentId',
      },
      constraints: false,
    });







//end loop



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

    db.enrollments.belongsTo(db.camp_sessions, {
      as: 'camp_session',
      foreignKey: {
        name: 'camp_sessionId',
      },
      constraints: false,
    });

    db.enrollments.belongsTo(db.pricing_plans, {
      as: 'pricing_plan',
      foreignKey: {
        name: 'pricing_planId',
      },
      constraints: false,
    });

    db.enrollments.belongsTo(db.age_groups, {
      as: 'age_group',
      foreignKey: {
        name: 'age_groupId',
      },
      constraints: false,
    });




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

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



  return enrollments;
};


