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

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"uploaded",


"processing",


"ready_for_selection",


"awaiting_payment",


"in_production",


"completed",


"rejected"

        ],

      },

selected_size: {
        type: DataTypes.ENUM,
      
      

        values: [

"20x30",


"30x40",


"40x50",


"50x70",


"60x80"

        ],

      },

selected_difficulty: {
        type: DataTypes.ENUM,
      
      

        values: [

"easy",


"medium",


"hard",


"expert"

        ],

      },

estimated_color_count: {
        type: DataTypes.INTEGER,
      
      

      },

estimated_price: {
        type: DataTypes.DECIMAL,
      
      

      },

instructions: {
        type: DataTypes.TEXT,
      
      

      },

ai_model_version: {
        type: DataTypes.TEXT,
      
      

      },

submitted_at: {
        type: DataTypes.DATE,
      
      

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

approved_at: {
        type: DataTypes.DATE,
      
      

      },

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

  custom_artwork_requests.associate = (db) => {


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

























    db.custom_artwork_requests.hasMany(db.ai_generation_jobs, {
      as: 'ai_generation_jobs_request',
      foreignKey: {
          name: 'requestId',
      },
      constraints: false,
    });




//end loop



    db.custom_artwork_requests.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });



    db.custom_artwork_requests.hasMany(db.file, {
      as: 'source_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.custom_artwork_requests.getTableName(),
        belongsToColumn: 'source_images',
      },
    });

    db.custom_artwork_requests.hasMany(db.file, {
      as: 'pattern_files',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.custom_artwork_requests.getTableName(),
        belongsToColumn: 'pattern_files',
      },
    });

    db.custom_artwork_requests.hasMany(db.file, {
      as: 'pattern_preview_images',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.custom_artwork_requests.getTableName(),
        belongsToColumn: 'pattern_preview_images',
      },
    });


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

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



  return custom_artwork_requests;
};


