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

name: {
        type: DataTypes.TEXT,
      
      

      },

mode_key: {
        type: DataTypes.ENUM,
      
      

        values: [

"classic",


"music",


"race",


"wheel_of_fortune",


"cat",


"manipulat",


"system_override",


"mirror",


"expedition",


"movie_studio",


"community"

        ],

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

      },

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

  game_modes.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_modes.hasMany(db.matches, {
      as: 'matches_mode',
      foreignKey: {
          name: 'modeId',
      },
      constraints: false,
    });













    db.game_modes.hasMany(db.leaderboard_entries, {
      as: 'leaderboard_entries_mode',
      foreignKey: {
          name: 'modeId',
      },
      constraints: false,
    });



//end loop





    db.game_modes.hasMany(db.file, {
      as: 'mode_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.game_modes.getTableName(),
        belongsToColumn: 'mode_images',
      },
    });


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

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



  return game_modes;
};


