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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

lufs_measured: {
        type: DataTypes.DECIMAL,
      
      

      },

true_peak_measured_db: {
        type: DataTypes.DECIMAL,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

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

  mastering_sessions.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.mastering_sessions.belongsTo(db.songs, {
      as: 'song',
      foreignKey: {
        name: 'songId',
      },
      constraints: false,
    });

    db.mastering_sessions.belongsTo(db.users, {
      as: 'requested_user',
      foreignKey: {
        name: 'requested_userId',
      },
      constraints: false,
    });

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

    db.mastering_sessions.belongsTo(db.assets, {
      as: 'input_mix_asset',
      foreignKey: {
        name: 'input_mix_assetId',
      },
      constraints: false,
    });

    db.mastering_sessions.belongsTo(db.assets, {
      as: 'result_master_asset',
      foreignKey: {
        name: 'result_master_assetId',
      },
      constraints: false,
    });

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




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

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



  return mastering_sessions;
};


