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

processed_at: {
        type: DataTypes.DATE,
      
      

      },

engine: {
        type: DataTypes.ENUM,
      
      

        values: [

"tesseract",


"google_vision",


"aws_textract",


"other"

        ],

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"success",


"partial",


"failed"

        ],

      },

invoice_number_text: {
        type: DataTypes.TEXT,
      
      

      },

seller_name_text: {
        type: DataTypes.TEXT,
      
      

      },

buyer_name_text: {
        type: DataTypes.TEXT,
      
      

      },

tin_number_text: {
        type: DataTypes.TEXT,
      
      

      },

invoice_date: {
        type: DataTypes.DATE,
      
      

      },

subtotal_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

vat_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

tot_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

total_amount: {
        type: DataTypes.DECIMAL,
      
      

      },

raw_text: {
        type: DataTypes.TEXT,
      
      

      },

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

  ocr_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.ocr_extractions.belongsTo(db.receipts, {
      as: 'receipt',
      foreignKey: {
        name: 'receiptId',
      },
      constraints: false,
    });

    db.ocr_extractions.belongsTo(db.merchants, {
      as: 'merchant',
      foreignKey: {
        name: 'merchantId',
      },
      constraints: false,
    });

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




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

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



  return ocr_extractions;
};


