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

artist_name: {
        type: DataTypes.TEXT,
      
      

      },

profile_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"solo_artist",


"group",


"label"

        ],

      },

legal_name: {
        type: DataTypes.TEXT,
      
      

      },

country: {
        type: DataTypes.TEXT,
      
      

      },

city: {
        type: DataTypes.TEXT,
      
      

      },

tax_residency: {
        type: DataTypes.TEXT,
      
      

      },

payout_currency: {
        type: DataTypes.TEXT,
      
      

      },

bio: {
        type: DataTypes.TEXT,
      
      

      },

website_url: {
        type: DataTypes.TEXT,
      
      

      },

vk_url: {
        type: DataTypes.TEXT,
      
      

      },

youtube_url: {
        type: DataTypes.TEXT,
      
      

      },

tiktok_url: {
        type: DataTypes.TEXT,
      
      

      },

instagram_url: {
        type: DataTypes.TEXT,
      
      

      },

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

  artist_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.artist_profiles.hasMany(db.releases, {
      as: 'releases_artist_profile',
      foreignKey: {
          name: 'artist_profileId',
      },
      constraints: false,
    });









    db.artist_profiles.hasMany(db.pitch_requests, {
      as: 'pitch_requests_artist_profile',
      foreignKey: {
          name: 'artist_profileId',
      },
      constraints: false,
    });



    db.artist_profiles.hasMany(db.royalty_reports, {
      as: 'royalty_reports_artist_profile',
      foreignKey: {
          name: 'artist_profileId',
      },
      constraints: false,
    });








    db.artist_profiles.hasMany(db.analytics_daily, {
      as: 'analytics_daily_artist_profile',
      foreignKey: {
          name: 'artist_profileId',
      },
      constraints: false,
    });














//end loop



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

    db.artist_profiles.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });



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


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

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



  return artist_profiles;
};


