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

const branchSchema = new Schema({
  companyId: {
    type: Schema.Types.ObjectId,
    ref: 'Company',  // Reference to Company model
    required: true
  },
  name: {
    type: String,
    required: true
  },
  type: {
    type: String,
    enum: ['store', 'shop'],
    default:'shop',
    required: true
  },
  defaultAction: {
    type: String,
    enum: ['selling', 'purchasing','producing','transfering','using','ordering'],
    default:'selling',
    required: true
  },
  considerStock: {
    type: Boolean,
      default:true,
    required: true
  },
  considerMonthlyExpense: {// like rent , worker not daily expense
    type: Boolean,
    default:true,
    required: true
  },
  considerSystemSale: {
    type: Boolean,
      default:true,
    required: true
  },
  considerSystemWithdrawal: {
    type: Boolean,
      default:true,
    required: true
  },
  considerSystemWithdrawalForSelling: {
    type: Boolean,
      default:true,
    required: true
  },
  storeBranchId: {
    type: Schema.Types.ObjectId,
    ref: 'Branch',  // Self-reference to the Branch model
    default: null,  // Use null to indicate no reference by default
    required: false
  },
  groupId: {
    type: Schema.Types.ObjectId,
    ref: 'BranchGroup',  // Reference to BranchGroup model
    default: null  // Default to null
  }
}, 
{ timestamps: true });

module.exports = mongoose.model('Branch', branchSchema);
