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

amount_due: {
        type: DataTypes.DECIMAL,
      
      

      },

amount_paid: {
        type: DataTypes.DECIMAL,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"pending",


"paid",


"failed",


"cancelled"

        ],

      },

pay_link_token: {
        type: DataTypes.TEXT,
      
      

      },

pay_link_expires_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payment_shares.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.payment_shares.belongsTo(db.payments, {
      as: 'payment',
      foreignKey: {
        name: 'paymentId',
      },
      constraints: false,
    });

    db.payment_shares.belongsTo(db.contract_participants, {
      as: 'contract_participant',
      foreignKey: {
        name: 'contract_participantId',
      },
      constraints: false,
    });

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




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

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



  return payment_shares;
};


