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

name: {
        type: DataTypes.TEXT,
      
      

      },

image_source: {
        type: DataTypes.ENUM,
      
      

        values: [

"cached_dataset",


"musicbrainz",


"lastfm",


"beatmap_background_fallback",


"none"

        ],

      },

image_url: {
        type: DataTypes.TEXT,
      
      

      },

external_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,
    },
  );

  artists.associate = (db) => {


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











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



    db.artists.hasMany(db.artist_stats, {
      as: 'artist_stats_artist',
      foreignKey: {
          name: 'artistId',
      },
      constraints: false,
    });








//end loop






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

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



  return artists;
};


