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

payment_code: {
        type: DataTypes.TEXT,
      
      

      },

beneficiary_name: {
        type: DataTypes.TEXT,
      
      

      },

beneficiary_document: {
        type: DataTypes.TEXT,
      
      

      },

amount_paid: {
        type: DataTypes.DECIMAL,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

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

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

    db.deductible_payments.belongsTo(db.dependents, {
      as: 'dependent',
      foreignKey: {
        name: 'dependentId',
      },
      constraints: false,
    });

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




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

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



  return deductible_payments;
};


