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

extraction_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"ocr_text",


"metadata",


"clauses",


"summary",


"issues",


"citations"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"queued",


"running",


"completed",


"failed"

        ],

      },

language: {
        type: DataTypes.TEXT,
      
      

      },

page_count: {
        type: DataTypes.INTEGER,
      
      

      },

result_text: {
        type: DataTypes.TEXT,
      
      

      },

started_at: {
        type: DataTypes.DATE,
      
      

      },

finished_at: {
        type: DataTypes.DATE,
      
      

      },

error_message: {
        type: DataTypes.TEXT,
      
      

      },

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

  file_extractions.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.file_extractions.belongsTo(db.files, {
      as: 'file',
      foreignKey: {
        name: 'fileId',
      },
      constraints: false,
    });




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

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



  return file_extractions;
};


