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

osu_beatmap_numeric: {
        type: DataTypes.INTEGER,
      
      

      },

difficulty_name: {
        type: DataTypes.TEXT,
      
      

      },

mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"osu"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"ranked",


"loved"

        ],

      },

playcount: {
        type: DataTypes.INTEGER,
      
      

      },

passcount: {
        type: DataTypes.INTEGER,
      
      

      },

star_rating: {
        type: DataTypes.DECIMAL,
      
      

      },

bpm: {
        type: DataTypes.DECIMAL,
      
      

      },

length_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

cs: {
        type: DataTypes.DECIMAL,
      
      

      },

ar: {
        type: DataTypes.DECIMAL,
      
      

      },

od: {
        type: DataTypes.DECIMAL,
      
      

      },

hp: {
        type: DataTypes.DECIMAL,
      
      

      },

last_synced_at: {
        type: DataTypes.DATE,
      
      

      },

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

  beatmaps.associate = (db) => {


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















    db.beatmaps.hasMany(db.game_rounds, {
      as: 'game_rounds_option_a_beatmap',
      foreignKey: {
          name: 'option_a_beatmapId',
      },
      constraints: false,
    });

    db.beatmaps.hasMany(db.game_rounds, {
      as: 'game_rounds_option_b_beatmap',
      foreignKey: {
          name: 'option_b_beatmapId',
      },
      constraints: false,
    });






//end loop



    db.beatmaps.belongsTo(db.beatmap_sets, {
      as: 'beatmap_set',
      foreignKey: {
        name: 'beatmap_setId',
      },
      constraints: false,
    });

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

    db.beatmaps.belongsTo(db.artists, {
      as: 'artist',
      foreignKey: {
        name: 'artistId',
      },
      constraints: false,
    });




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

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



  return beatmaps;
};


