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

nickname: {
        type: DataTypes.TEXT,
      
      

      },

rsvp_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"going",


"maybe",


"not_going"

        ],

      },

attendance_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"attended",


"absent",


"no_fee"

        ],

      },

payment_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"unpaid",


"paid",


"exempt"

        ],

      },

seed_tier_for_balance: {
        type: DataTypes.INTEGER,
      
      

      },

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

  game_guests.associate = (db) => {


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


















    db.game_guests.hasMany(db.game_team_assignments, {
      as: 'game_team_assignments_guest',
      foreignKey: {
          name: 'guestId',
      },
      constraints: false,
    });


    db.game_guests.hasMany(db.game_attendances, {
      as: 'game_attendances_guest',
      foreignKey: {
          name: 'guestId',
      },
      constraints: false,
    });



    db.game_guests.hasMany(db.game_payments, {
      as: 'game_payments_guest',
      foreignKey: {
          name: 'guestId',
      },
      constraints: false,
    });








//end loop



    db.game_guests.belongsTo(db.games, {
      as: 'game',
      foreignKey: {
        name: 'gameId',
      },
      constraints: false,
    });

    db.game_guests.belongsTo(db.users, {
      as: 'added_by_user',
      foreignKey: {
        name: 'added_by_userId',
      },
      constraints: false,
    });

    db.game_guests.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return game_guests;
};


