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

gender: {
        type: DataTypes.ENUM,
      
      

        values: [

"female",


"male",


"non_binary"

        ],

      },

first_name: {
        type: DataTypes.TEXT,
      
      

      },

last_name: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

level: {
        type: DataTypes.INTEGER,
      
      

      },

experience_points: {
        type: DataTypes.DECIMAL,
      
      

      },

money_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

pix_balance: {
        type: DataTypes.DECIMAL,
      
      

      },

reputation_score: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  player_profiles.associate = (db) => {


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















    db.player_profiles.hasMany(db.npc_relationships, {
      as: 'npc_relationships_player_profile',
      foreignKey: {
          name: 'player_profileId',
      },
      constraints: false,
    });
























    db.player_profiles.hasMany(db.farm_plots, {
      as: 'farm_plots_owner_profile',
      foreignKey: {
          name: 'owner_profileId',
      },
      constraints: false,
    });





    db.player_profiles.hasMany(db.fishing_catches, {
      as: 'fishing_catches_player_profile',
      foreignKey: {
          name: 'player_profileId',
      },
      constraints: false,
    });










//end loop



    db.player_profiles.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.player_profiles.belongsTo(db.locations, {
      as: 'home_location',
      foreignKey: {
        name: 'home_locationId',
      },
      constraints: false,
    });



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


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

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



  return player_profiles;
};


