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

name: {
        type: DataTypes.TEXT,
      
      

      },

target: {
        type: DataTypes.ENUM,
      
      

        values: [

"streaming",


"radio_broadcast",


"club_loud",


"genre_aware"

        ],

      },

lufs_target: {
        type: DataTypes.DECIMAL,
      
      

      },

true_peak_db: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  mastering_presets.associate = (db) => {


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























    db.mastering_presets.hasMany(db.mastering_sessions, {
      as: 'mastering_sessions_preset',
      foreignKey: {
          name: 'presetId',
      },
      constraints: false,
    });







//end loop



    db.mastering_presets.belongsTo(db.genres, {
      as: 'genre',
      foreignKey: {
        name: 'genreId',
      },
      constraints: false,
    });

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




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

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



  return mastering_presets;
};


