const mongoose = require('mongoose');

const bankTransactionSchema = new mongoose.Schema(
  {
    companyId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Company',
      required: true
    },
    branchId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Branch',
      required: true
    },
    bankAccountId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'BankAccount',
      required: true
    },
    transactionType: {
      type: String,
      enum: ['deposit', 'withdrawal'],
      required: true
    },
    amount: {
      type: Number,
      required: true
    },
    balance: {
      type: Number,
      required: true
    }
  },
  { timestamps: true } // Automatically adds createdAt and updatedAt fields
);

const BankTransaction = mongoose.model('BankTransaction', bankTransactionSchema);

module.exports = BankTransaction;
