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

name: {
        type: DataTypes.TEXT,
      
      

      },

track_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"vocal",


"drums",


"bass",


"instrument",


"fx",


"bus",


"master"

        ],

      },

instrument: {
        type: DataTypes.ENUM,
      
      

        values: [

"voice",


"piano",


"log_drum",


"synth",


"brass",


"guitar",


"traditional_drums",


"perc",


"pads",


"strings",


"other"

        ],

      },

volume_db: {
        type: DataTypes.DECIMAL,
      
      

      },

pan: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

      },

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

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

    db.tracks.belongsTo(db.assets, {
      as: 'source_asset',
      foreignKey: {
        name: 'source_assetId',
      },
      constraints: false,
    });

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




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

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



  return tracks;
};


