const mongoose = require('mongoose');

const transactionSchema = new mongoose.Schema({
    amount: {
        type: Number,
        required: true
    },
    reference: {
        type: String,
        required: true
    },
    type: {
        type: String,
        enum: ['credit', 'debit'],
        required: true
    },
    method: {
        type: String,
        enum: ['wallet', 'paystack'],
        required: true
    },
    purpose: {
      type: String,
      enum: ['deposit', 'withdrawal', 'purchase', 'refund', 'referral'],
      required: true
    },
    sender: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Account',
      required: true
    },
    receiver: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Account',
      required: true
    },
    paystackData: {
      type: Object,
    },
    status: {
      type: String,
      enum: ['pending', 'success', 'failed', 'abandoned'],
      default: 'pending'
    },
    description: {
      type: String,
    },
})
transactionSchema.index({ senderId: 1 });
transactionSchema.index({ receiverId: 1 });
transactionSchema.index({ status: 1 });
module.exports = mongoose.model("Transaction", transactionSchema);