<?php

namespace App\Modules\PaxInformationRoomPassenger\Application\UpdateRoomPassenger;

class UpdateRoomPassengerBookingExtraTree
{
    public function __construct(
        public array $bookingExtra = [],
    ) {}

    public function extras()
    {
        return array_values($this->bookingExtra);
    }

    public function passengerFromExtra($idBookingExtra)
    {
        return $this->bookingExtra[$idBookingExtra]['bookingExtraPassengers'];
    }

    public function addBookingExtras(array $bookingExtras)
    {
        foreach ($bookingExtras as $be) {
            $this->bookingExtra[$be->Id_BookingExtra] = [
                'value' => $be,
                'rooms' => [],
                'bookingExtraPassengers' => []
            ];
        }
    }

    public function addBookingExtraPassengers(array $bookingExtraPassengers)
    {
        foreach ($bookingExtraPassengers as $bep) {
            if (!isset($this->bookingExtra[$bep->Id_BookingExtra])) {
                continue;
            }
            $this->bookingExtra[$bep->Id_BookingExtra]['bookingExtraPassengers'][] = $bep;
        }
    }

    public function addRooms(array $rooms)
    {
        foreach ($rooms as $room) {
            if ($room->Id_BookingExtra == 0) {
                continue;
            }
            $this->bookingExtra[$room->Id_BookingExtra]['rooms'][$room->Id_Room] = $room;
        }
    }
}
