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

name: {
        type: DataTypes.TEXT,
      
      

      },

theme_title: {
        type: DataTypes.TEXT,
      
      

      },

theme_summary: {
        type: DataTypes.TEXT,
      
      

      },

theme_scripture_reference: {
        type: DataTypes.TEXT,
      
      

      },

theme_scripture_text: {
        type: DataTypes.TEXT,
      
      

      },

start_datetime: {
        type: DataTypes.DATE,
      
      

      },

end_datetime: {
        type: DataTypes.DATE,
      
      

      },

day_camp_hours: {
        type: DataTypes.TEXT,
      
      

      },

third_shift_hours: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  camp_sessions.associate = (db) => {


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








    db.camp_sessions.hasMany(db.weekly_themes, {
      as: 'weekly_themes_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });


    db.camp_sessions.hasMany(db.pricing_plans, {
      as: 'pricing_plans_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });


    db.camp_sessions.hasMany(db.fee_rules, {
      as: 'fee_rules_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });




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



    db.camp_sessions.hasMany(db.waiver_documents, {
      as: 'waiver_documents_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });




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



    db.camp_sessions.hasMany(db.special_trips, {
      as: 'special_trips_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });


    db.camp_sessions.hasMany(db.end_of_summer_trip_options, {
      as: 'end_of_summer_trip_options_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });



    db.camp_sessions.hasMany(db.activity_blocks, {
      as: 'activity_blocks_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });



    db.camp_sessions.hasMany(db.staff_assignments, {
      as: 'staff_assignments_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });


    db.camp_sessions.hasMany(db.announcements, {
      as: 'announcements_camp_session',
      foreignKey: {
          name: 'camp_sessionId',
      },
      constraints: false,
    });



//end loop



    db.camp_sessions.belongsTo(db.campuses, {
      as: 'campus',
      foreignKey: {
        name: 'campusId',
      },
      constraints: false,
    });




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

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



  return camp_sessions;
};


