import mongoose from 'mongoose';

export const MOVEMENT_TYPES = ['CASH_IN', 'CASH_OUT'];
export const MOVEMENT_REASONS = [
  'PETTY_CASH',
  'BANK_DEPOSIT',
  'CHANGE_FUND',
  'EXPENSE',
  'OWNER_WITHDRAWAL',
  'OTHER',
];

const cashMovementSchema = new mongoose.Schema(
  {
    shift: { type: mongoose.Schema.Types.ObjectId, ref: 'Shift', required: true, index: true },
    type: { type: String, enum: MOVEMENT_TYPES, required: true },
    amount: { type: Number, required: true, min: 0.01 },
    reason: { type: String, enum: MOVEMENT_REASONS, required: true },
    note: { type: String, default: '', trim: true, maxlength: 300 },
    createdBy: {
      id: { type: mongoose.Schema.Types.ObjectId, ref: 'Admin' },
      name: { type: String, default: '' },
    },
  },
  { timestamps: true }
);

export default mongoose.model('CashMovement', cashMovementSchema);
