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

pitch_title: {
        type: DataTypes.TEXT,
      
      

      },

pitch_text: {
        type: DataTypes.TEXT,
      
      

      },

mood: {
        type: DataTypes.TEXT,
      
      

      },

similar_artists: {
        type: DataTypes.TEXT,
      
      

      },

achievements: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"sent",


"under_review",


"accepted",


"rejected"

        ],

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

decided_at: {
        type: DataTypes.DATE,
      
      

      },

decision_notes: {
        type: DataTypes.TEXT,
      
      

      },

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

  pitch_requests.associate = (db) => {

    db.pitch_requests.belongsToMany(db.playlists, {
      as: 'target_playlists',
      foreignKey: {
        name: 'pitch_requests_target_playlistsId',
      },
      constraints: false,
      through: 'pitch_requestsTarget_playlistsPlaylists',
    });

    db.pitch_requests.belongsToMany(db.playlists, {
      as: 'target_playlists_filter',
      foreignKey: {
        name: 'pitch_requests_target_playlistsId',
      },
      constraints: false,
      through: 'pitch_requestsTarget_playlistsPlaylists',
    });


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












































//end loop



    db.pitch_requests.belongsTo(db.tracks, {
      as: 'track',
      foreignKey: {
        name: 'trackId',
      },
      constraints: false,
    });

    db.pitch_requests.belongsTo(db.artist_profiles, {
      as: 'artist_profile',
      foreignKey: {
        name: 'artist_profileId',
      },
      constraints: false,
    });

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




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

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



  return pitch_requests;
};


