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

provider: {
        type: DataTypes.ENUM,
      
      

        values: [

"stripe"

        ],

      },

transaction_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"payment_intent",


"charge",


"refund",


"invoice_payment"

        ],

      },

provider_reference: {
        type: DataTypes.TEXT,
      
      

      },

amount: {
        type: DataTypes.DECIMAL,
      
      

      },

currency: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"requires_payment_method",


"requires_action",


"processing",


"succeeded",


"failed",


"refunded",


"cancelled"

        ],

      },

processed_at: {
        type: DataTypes.DATE,
      
      

      },

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

  payment_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.payment_transactions.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });

    db.payment_transactions.belongsTo(db.customers, {
      as: 'customer',
      foreignKey: {
        name: 'customerId',
      },
      constraints: false,
    });

    db.payment_transactions.belongsTo(db.service_requests, {
      as: 'service_request',
      foreignKey: {
        name: 'service_requestId',
      },
      constraints: false,
    });




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

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



  return payment_transactions;
};


