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

depart_datetime: {
        type: DataTypes.DATE,
      
      

      },

return_datetime: {
        type: DataTypes.DATE,
      
      

      },

price_per_student: {
        type: DataTypes.DECIMAL,
      
      

      },

capacity: {
        type: DataTypes.INTEGER,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"planned",


"open",


"full",


"cancelled",


"completed"

        ],

      },

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

  field_trip_events.associate = (db) => {


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



















    db.field_trip_events.hasMany(db.trip_registrations, {
      as: 'trip_registrations_field_trip_event',
      foreignKey: {
          name: 'field_trip_eventId',
      },
      constraints: false,
    });










//end loop



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

    db.field_trip_events.belongsTo(db.field_trip_catalog, {
      as: 'field_trip',
      foreignKey: {
        name: 'field_tripId',
      },
      constraints: false,
    });

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




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

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



  return field_trip_events;
};


