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

osu_user_numeric: {
        type: DataTypes.INTEGER,
      
      

      },

osu_username: {
        type: DataTypes.TEXT,
      
      

      },

avatar_url: {
        type: DataTypes.TEXT,
      
      

      },

profile_url: {
        type: DataTypes.TEXT,
      
      

      },

banner_url: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"missing",


"disabled"

        ],

      },

last_synced_at: {
        type: DataTypes.DATE,
      
      

      },

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

  mappers.associate = (db) => {


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











    db.mappers.hasMany(db.beatmaps, {
      as: 'beatmaps_mapper',
      foreignKey: {
          name: 'mapperId',
      },
      constraints: false,
    });


    db.mappers.hasMany(db.mapper_stats, {
      as: 'mapper_stats_mapper',
      foreignKey: {
          name: 'mapperId',
      },
      constraints: false,
    });









//end loop






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

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



  return mappers;
};


