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

document_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"informe_rendimentos_empregador",


"informe_rendimentos_banco",


"informe_rendimentos_corretora",


"informe_previdencia",


"informe_saude",


"recibo_medico",


"mensalidade_escolar",


"carne_leao",


"escritura_imovel",


"dimob",


"nf_servicos",


"informe_criptoativos",


"outro"

        ],

      },

file_name: {
        type: DataTypes.TEXT,
      
      

      },

storage_url: {
        type: DataTypes.TEXT,
      
      

      },

extraction_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pendente",


"processando",


"extraido",


"falhou",


"confirmado"

        ],

      },

extraction_confidence: {
        type: DataTypes.INTEGER,
      
      

      },

extracted_data_json: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

issuer_name: {
        type: DataTypes.TEXT,
      
      

      },

issuer_cnpj: {
        type: DataTypes.TEXT,
      
      

      },

reference_year: {
        type: DataTypes.INTEGER,
      
      

      },

uploaded_at: {
        type: DataTypes.DATE,
      
      

      },

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

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

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




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

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



  return documents;
};


