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

request_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"generate_beat_from_text",


"generate_beat_from_vocals",


"arrangement_builder",


"vocal_processing",


"auto_mix",


"mastering",


"cover_art",


"song_naming",


"metadata_tagging",


"genre_suggestion",


"make_it_amapiano"

        ],

      },

prompt_text: {
        type: DataTypes.TEXT,
      
      

      },

target_bpm: {
        type: DataTypes.INTEGER,
      
      

      },

target_key: {
        type: DataTypes.TEXT,
      
      

      },

mood: {
        type: DataTypes.ENUM,
      
      

        values: [

"happy",


"sad",


"spiritual",


"energetic",


"romantic",


"chill",


"aggressive"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed",


"canceled"

        ],

      },

queued_at: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

compute_seconds: {
        type: DataTypes.INTEGER,
      
      

      },

estimated_cost: {
        type: DataTypes.DECIMAL,
      
      

      },

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

  generation_requests.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.generation_requests.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.generation_requests.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });

    db.generation_requests.belongsTo(db.songs, {
      as: 'song',
      foreignKey: {
        name: 'songId',
      },
      constraints: false,
    });

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

    db.generation_requests.belongsTo(db.ai_models, {
      as: 'model',
      foreignKey: {
        name: 'modelId',
      },
      constraints: false,
    });

    db.generation_requests.belongsTo(db.assets, {
      as: 'input_asset',
      foreignKey: {
        name: 'input_assetId',
      },
      constraints: false,
    });

    db.generation_requests.belongsTo(db.genres, {
      as: 'target_genre',
      foreignKey: {
        name: 'target_genreId',
      },
      constraints: false,
    });

    db.generation_requests.belongsTo(db.assets, {
      as: 'output_asset',
      foreignKey: {
        name: 'output_assetId',
      },
      constraints: false,
    });

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




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

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



  return generation_requests;
};


