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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requested",


"confirmed",


"cancelled"

        ],

      },

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

      },

registered_datetime: {
        type: DataTypes.DATE,
      
      

      },

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

  trip_registrations.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.trip_registrations.belongsTo(db.field_trip_events, {
      as: 'field_trip_event',
      foreignKey: {
        name: 'field_trip_eventId',
      },
      constraints: false,
    });

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




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

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



  return trip_registrations;
};


