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

name: {
        type: DataTypes.TEXT,
      
      

      },

playlist_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"default",


"seasonal_christmas",


"seasonal_other",


"mode_specific"

        ],

      },

auto_activate: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

active_from: {
        type: DataTypes.DATE,
      
      

      },

active_to: {
        type: DataTypes.DATE,
      
      

      },

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

  music_playlists.associate = (db) => {


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





























    db.music_playlists.hasMany(db.music_tracks, {
      as: 'music_tracks_playlist',
      foreignKey: {
          name: 'playlistId',
      },
      constraints: false,
    });









//end loop





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


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

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



  return music_playlists;
};


