const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const BankAccountSchema = new Schema({
  accountNumber: {
    type: String,
    required: true,
    unique: true,  // Ensure account numbers are unique
    trim: true
  },
  bankName: {
    type: String,
    required: true,
    trim: true
  },
  balance: {
    type: Number,
    required: true,
    default: 0  // Initialize balance to 0
  },
  accountHolderName: {
    type: String,
    required: true,
    trim: true
  },
  branchId: {
    type: Schema.Types.ObjectId,
    ref: 'Branch',  // Reference to Branch model
    required: true
  },
  companyId: {
    type: Schema.Types.ObjectId,
    ref: 'Company',  // Reference to Company model
    required: true
  }
}, {
  timestamps: true  // Automatically adds createdAt and updatedAt fields
});

module.exports = mongoose.model('BankAccount', BankAccountSchema);
