'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class TransactionPayment extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
       TransactionPayment.belongsTo(models.Transaction, {
        foreignKey: 'transactionId',
        as: 'transaction'
      });
      TransactionPayment.hasMany(models.MpesaPayment, { foreignKey: 'transactionPaymentId', as: 'mpesaPayments' });
     
    }
  }
  TransactionPayment.init({
    transactionId: DataTypes.INTEGER,
    paymentMethod: DataTypes.STRING,
    amount: DataTypes.DECIMAL,
    paymentDate: DataTypes.DATE,
    status: DataTypes.STRING,
    referenceNumber: DataTypes.STRING,
    currency: DataTypes.STRING,
    processorDetails: DataTypes.JSON,
    isRefund: DataTypes.BOOLEAN
  }, {
    sequelize,
    modelName: 'TransactionPayment',
  });
  return TransactionPayment;
};