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

name: {
        type: DataTypes.TEXT,
      
      

      },

duration_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

order_index: {
        type: DataTypes.INTEGER,
      
      

      },

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

  music_tracks.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.music_tracks.belongsTo(db.music_playlists, {
      as: 'playlist',
      foreignKey: {
        name: 'playlistId',
      },
      constraints: false,
    });



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


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

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



  return music_tracks;
};


