Per code review feedback from @objecttothis:
- Create app/Enums/RewardOperation.php with Deduct, Restore, Adjust cases
- Update Reward_lib::adjustRewardPoints() to use RewardOperation enum
instead of string parameter for operation type
- Update tests to use RewardOperation::Deduct/Restore enum values
Benefits:
- Type safety: Cannot pass invalid operation string
- IDE autocomplete support for operation types
- Compile-time error for typos instead of runtime failure
- Self-documenting code with explicit cases
CodeRabbit issues addressed:
1. Negative points prevention in Reward_lib:
- adjustRewardPoints(): Validate sufficient balance before deduct/adjust
- handleCustomerChange(): Cap charge at available points, add 'insufficient' flag
- adjustRewardDelta(): Validate sufficient points for positive adjustments
2. Sale.php fixes:
- Add null coalescing for reward points in processPaymentType()
- Validate giftcard payment format before accessing array index
- Remove unused loop variables $paymentId and $line
- Add null check for deleted customer in delete() method
- Log warnings when insufficient points detected
3. Test coverage:
- Add test for exact points match (hasSufficientPoints)
- Add tests for insufficient points scenarios
- Add tests for negative adjustment (refund)
- Add tests for handleCustomerChange caps
All changes prevent customers from having negative reward point balances.