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,
      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed",


"canceled"

        ],

      },

requested_count: {
        type: DataTypes.INTEGER,
      
      

      },

difficulty_target: {
        type: DataTypes.ENUM,
      
      

        values: [

"mixed",


"very_easy",


"easy",


"medium",


"hard",


"very_hard"

        ],

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

prompt: {
        type: DataTypes.TEXT,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

      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.users, {
      as: 'owner_user',
      foreignKey: {
        name: 'owner_userId',
      },
      constraints: false,
    });

    db.ai_generation_jobs.belongsTo(db.chapters, {
      as: 'chapter',
      foreignKey: {
        name: 'chapterId',
      },
      constraints: false,
    });




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

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



  return ai_generation_jobs;
};


