const mongoose = require('mongoose');

const invoiceSchema = new mongoose.Schema({
  invoice_number: { type: String, required: true, unique: true },
  customer_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer', required: true },
  trip_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Trip' },
  issue_date: { type: Date, required: true },
  due_date: { type: Date, required: true },
  subtotal: { type: Number, default: 0 },
  tax_rate: { type: Number, default: 0 },
  tax_amount: { type: Number, default: 0 },
  discount: { type: Number, default: 0 },
  total_amount: { type: Number, default: 0 },
  status: { type: String, enum: ['draft','sent','paid','overdue','cancelled'], default: 'draft' },
  notes: String,
}, { timestamps: true });

module.exports = mongoose.model('Invoice', invoiceSchema);
