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

job_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"crawl",


"transcribe",


"extract_text",


"reembed",


"policy_update",


"behavioral_science_update"

        ],

      },

job_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"scheduled",


"running",


"completed",


"failed",


"awaiting_approval"

        ],

      },

scheduled_for: {
        type: DataTypes.DATE,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

job_summary: {
        type: DataTypes.TEXT,
      
      

      },

job_log: {
        type: DataTypes.TEXT,
      
      

      },

approval_required: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  refresh_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.refresh_jobs.belongsTo(db.knowledge_sources, {
      as: 'knowledge_source',
      foreignKey: {
        name: 'knowledge_sourceId',
      },
      constraints: false,
    });




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

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



  return refresh_jobs;
};


