const mongoose = require('mongoose');

const orderSchema = new mongoose.Schema(
  {
    companyId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Company', // Reference to the Company model
      required: true,
    },
    branchId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Branch', // Reference to the Branch model
      required: true,
    },
 
    // transactionId: {
    //   type: mongoose.Schema.Types.ObjectId,
    //   ref: 'Transaction', 
    //   required: true,
    // },

    itemName: {
      type: String,
      required: true,
      trim: true,
    },
    customerName: {
      type: String,
      required: true,
      trim: true,
    },
    advancePayment: {
      type: Number,
      required: true,
      min: 0,
    }, 
    remainingPayment: {
      type: Number,
      required: false,
      min: 0,
    },

    status: { // closed or not or paid fully or not
      type: Boolean,
      required: true,
     default:false,
    },

    initialDate: {
      type: Date,
      required: true,
      default: Date.now, // Default to current date
    },
    closingDate: {
      type: Date,
      required: false,
    },
  },
  {
    timestamps: true, // Automatically adds `createdAt` and `updatedAt`
  }
);

module.exports = mongoose.model('Order', orderSchema);
