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

name: {
        type: DataTypes.TEXT,
      
      

      },

role: {
        type: DataTypes.ENUM,
      
      

        values: [

"primary_artist",


"featured_artist",


"producer",


"composer",


"lyricist",


"mixer",


"mastering_engineer",


"session_musician"

        ],

      },

spotify_artist_url: {
        type: DataTypes.TEXT,
      
      

      },

apple_artist_url: {
        type: DataTypes.TEXT,
      
      

      },

society_identifier: {
        type: DataTypes.TEXT,
      
      

      },

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

  track_contributors.associate = (db) => {


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












































//end loop



    db.track_contributors.belongsTo(db.tracks, {
      as: 'track',
      foreignKey: {
        name: 'trackId',
      },
      constraints: false,
    });

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




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

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



  return track_contributors;
};


