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

job_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed",


"cancelled"

        ],

      },

provider: {
        type: DataTypes.TEXT,
      
      

      },

provider_job_ref: {
        type: DataTypes.TEXT,
      
      

      },

runtime_seconds: {
        type: DataTypes.DECIMAL,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

queued_at: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

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

  ai_generation_jobs.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.ai_generation_jobs.belongsTo(db.custom_artwork_requests, {
      as: 'request',
      foreignKey: {
        name: 'requestId',
      },
      constraints: false,
    });




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

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



  return ai_generation_jobs;
};


