const mongoose = require('mongoose');
const { Schema } = mongoose;

const paymentHistorySchema = new Schema({
    customerId: {
        type: Schema.Types.ObjectId,
        ref: 'Customer', // Reference to the Customer collection
        required: true,
    },
    orderId: {
        type: Schema.Types.ObjectId,
        ref: 'CafeOrder', 
        required: false,
    },
    paid: {
        type: Number,
        default: 0, // Default debit is 0
    },
    credit: {
        type: Number,
        default: 0, // Default credit is 0
    },
    date: {
        type: Date,
        default: Date.now, // Default to current date and time
    },
    description: {
        type: String,
        trim: true, // Remove leading/trailing whitespace
    },
 
}, { timestamps: true }); // Enable timestamps (createdAt, updatedAt)

const PaymentHistory = mongoose.model('PaymentHistory', paymentHistorySchema);

module.exports = PaymentHistory;