# Family Booking Detection Issue ## Problem Description The current family booking detection logic in `BookingCreateDto::isFamilyBooking()` has a critical flaw that causes incorrect classification of booking types, leading to wrong insurance options being displayed. ### Current Logic (FLAWED) ```php // Current implementation in BookingCreateDto::isFamilyBooking() $adults = 0; // Count of participants >= 18 years $youngPeople = 0; // Count of participants <= 20 years foreach ($this->participants as $participant) { $age = $participant->getAge($travelStartDate); if ($age >= 18) { ++$adults; } if ($age <= 20) { ++$youngPeople; } } $isFamily = ($adults >= 1 && $adults <= 2) && ($youngPeople >= 1); ``` ### The Problem **Overlapping Age Ranges**: The current logic creates overlapping age categories: - **Adults**: ≥18 years - **Young people**: ≤20 years This means participants aged 18-20 are counted as **BOTH** adults AND young people, causing incorrect family booking detection. ### Example Scenario **Booking with 2 participants:** - **Participant 1**: Born 1980 (age 44 at travel time) - **Participant 2**: Born 2000 (age 24 at travel time) **Current logic result:** - `adults = 2` (both participants ≥18) - `youngPeople = 1` (the 24-year-old ≤20) - `isFamily = (2 >= 1 && 2 <= 2) && (1 >= 1) = true` ❌ **Expected result:** This should be classified as an **individual/couple booking**, not a family booking. ## Impact 1. **Wrong insurance options**: Family insurances are shown for individual bookings 2. **User confusion**: Customers see inappropriate insurance options 3. **Business logic errors**: Pricing and eligibility calculations are incorrect ## Suggested Solutions ### Option 1: Non-Overlapping Age Ranges (Recommended) ```php // Suggested implementation $adults = 0; // Count of participants >= 18 years $children = 0; // Count of participants < 18 years foreach ($this->participants as $participant) { $age = $participant->getAge($travelStartDate); if ($age >= 18) { ++$adults; } else { ++$children; } } $isFamily = ($adults >= 1) && ($children >= 1); ``` **Benefits:** - No overlapping age ranges - Clear distinction between adults and children - Matches insurance industry standards ### Option 2: Insurance-Specific Age Ranges ```php // Alternative implementation based on insurance requirements $adults = 0; // Count of participants >= 18 years $minors = 0; // Count of participants < 18 years foreach ($this->participants as $participant) { $age = $participant->getAge($travelStartDate); if ($age >= 18) { ++$adults; } elseif ($age < 18) { ++$minors; } // Note: 18+ year olds are not counted as minors } $isFamily = ($adults >= 1) && ($minors >= 1); ``` ### Option 3: Configurable Age Thresholds ```php // More flexible approach with configurable thresholds private const ADULT_AGE_THRESHOLD = 18; private const CHILD_AGE_THRESHOLD = 18; // Same as adult threshold for non-overlap $adults = 0; $children = 0; foreach ($this->participants as $participant) { $age = $participant->getAge($travelStartDate); if ($age >= self::ADULT_AGE_THRESHOLD) { ++$adults; } elseif ($age < self::CHILD_AGE_THRESHOLD) { ++$children; } } $isFamily = ($adults >= 1) && ($children >= 1); ``` ## Business Rules to Clarify Before implementing a solution, the following business rules need to be clarified: 1. **What defines a "family booking"?** - Must have at least 1 adult (≥18) and at least 1 child (<18)? - Or can it be 2 adults with children? - Or any booking with children regardless of adult count? 2. **Age thresholds:** - Should 18-year-olds be considered adults or children? - Are there different rules for different types of services? 3. **Edge cases:** - What about bookings with only adults (couples)? - What about bookings with only children (group bookings)? ## Implementation Notes - The fix should be implemented in `src/Form/Model/BookingCreateDto.php` - Update the `isFamilyBooking()` method - Add comprehensive unit tests for edge cases - Consider adding configuration options for age thresholds - Update documentation to reflect the new business rules ## Testing Scenarios After implementation, test these scenarios: 1. **Single adult** (should be individual booking) 2. **Two adults** (should be couple booking, not family) 3. **One adult + one child** (should be family booking) 4. **Two adults + one child** (should be family booking) 5. **Only children** (edge case - clarify business rule) 6. **18-year-old participant** (edge case - clarify classification) ## Related Files - `src/Form/Model/BookingCreateDto.php` - Main implementation - `src/Service/InsuranceMatchingService.php` - Uses family booking detection - `tests/Form/Model/BookingCreateDtoTest.php` - Unit tests (to be updated)