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

format: {
        type: DataTypes.ENUM,
      
      

        values: [

"wav",


"mp3",


"stems_zip"

        ],

      },

quality: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"standard",


"studio"

        ],

      },

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

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"processing",


"completed",


"failed"

        ],

      },

requested_at: {
        type: DataTypes.DATE,
      
      

      },

completed_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

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

    db.exports.belongsTo(db.assets, {
      as: 'export_asset',
      foreignKey: {
        name: 'export_assetId',
      },
      constraints: false,
    });

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




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

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



  return exports;
};


