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

job_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"open_finance_import",


"brokerage_import",


"govbr_import",


"sefaz_import",


"pdf_extraction",


"ai_classification_batch",


"risk_analysis",


"dec_generation",


"pdf_generation",


"excel_generation"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"succeeded",


"failed",


"canceled"

        ],

      },

attempt: {
        type: DataTypes.INTEGER,
      
      

      },

input_json: {
        type: DataTypes.TEXT,
      
      

      },

output_json: {
        type: DataTypes.TEXT,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  job_runs.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.job_runs.belongsTo(db.declarations, {
      as: 'declaration',
      foreignKey: {
        name: 'declarationId',
      },
      constraints: false,
    });

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




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

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



  return job_runs;
};


