const mongoose = require('mongoose');

const transactionDetailSchema = new mongoose.Schema({
  transactionId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Transaction',
    required: true
  },
  companyId: { type: mongoose.Schema.Types.ObjectId, ref: 'Company', required: true },
  branchId: { type: mongoose.Schema.Types.ObjectId, ref: 'Branch', required: true },


  itemId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Item',
    required: true
  },
 
  name: {
    type: String,
    required: true
  },
  code: {
    type: String,
    required: true
  },
  quantity: {
    type: Number,
    required: true
  },
  balance: {
    type: Number,
    required: true
  },
  avg_price: {
    type: Number
   
  },
  price: {
    type: Number,
    required: true
  },
  profit: {
    type: Number
  },

  profitMargin :{
    type: Number
  },
  total: {
    type: Number,
    required: true
  },
  transactionType: { // New field added to store the transaction type
    type: String,
    enum: ['ordering','selling', 'purchasing','using','producing'], 
   required: true
  },
 // orderStatus:{type:String,enum:['par-paid','paid'],required:false},
 orderId:{ type: mongoose.Schema.Types.ObjectId, ref: 'Order', required: false }
}, { timestamps: true });

module.exports = mongoose.model('TransactionDetail', transactionDetailSchema);
