const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const FinancialSummarySchema = new Schema({
  companyId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Company', // Assuming you have a Company model
    required: true
  },
  branchId: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Branch', // Assuming you have a Branch model
    required: true
  },
  stockValue: {
    type: Number,
    required: true,
    default: 0
  },
  storeWithdrawal: {// for using
    type: Number,
    required: true,
    default: 0
  },
  storeWithdrawalForSelling:{// for selling
    type: Number,
    required: true,
    default: 0
  },
  totalSales: { // sumed up from transaction
    type: Number,
    required: true,
    default: 0
  },
  toDaySale: {  // from cashier record
    type: Number,
    required: true,
    default: 0
  },
  totalPurchases: {
    type: Number,
    required: true,
    default: 0
  },
  totalExpense: {
    type: Number,
    required: true,
    default: 0
  },

  orderAdvance: {
    type: Number,
    required: true,
    default: 0
  },
  orderRemaining: {
    type: Number,
    required: true,
    default: 0
  },
  bankDeposit: {
    type: Number,
    required: true,
    default: 0
  },
  bankWithdraw: {
    type: Number,
    required: true,
    default: 0
  },

  cash: {
    type: Number,
    required: false, // Not required
    default: 0
  }, 
  bank: {
    type: Number,
    required: false, // Not required
    default: 0
  },
  credit: {
    type: Number,
    required: false, // Not required
    default: 0
  },
  other: {
    type: Number,
    required: false, // Not required
    default: 0
  },

  dailyNetProfitUsingSystem: {
    type: Number,
    required: true,
    default: 0
  },  
  dailyNetProfitUsingCashier: {
    type: Number,
    required: true,
    default: 0
  }
  
}, {
  timestamps: true // Automatically adds createdAt and updatedAt fields
});

module.exports = mongoose.model('FinancialSummary', FinancialSummarySchema);
