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

transaction_date: {
        type: DataTypes.DATE,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

direction: {
        type: DataTypes.ENUM,
      
      

        values: [

"credit",


"debit"

        ],

      },

ai_category: {
        type: DataTypes.TEXT,
      
      

      },

ir_field: {
        type: DataTypes.TEXT,
      
      

      },

ir_form: {
        type: DataTypes.TEXT,
      
      

      },

taxation_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"tributavel",


"isento",


"exclusivo_fonte",


"nao_tributavel"

        ],

      },

confidence_score: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

      },

review_reason: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.transactions.belongsTo(db.data_sources, {
      as: 'data_source',
      foreignKey: {
        name: 'data_sourceId',
      },
      constraints: false,
    });

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




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

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



  return transactions;
};


