<?php
/**
 * BookiFlex Payment Extension
 *
 * @package    BookiFlex
 * @subpackage Payment
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */


declare(strict_types=1);
namespace BookiFlex\Extensions\Payment\Provider;

use BookiFlex\Core\Contract\Payment\PaymentAllocationInterface;
use BookiFlex\Core\Contract\Payment\PaymentAllocationProviderInterface;
use BookiFlex\Core\Model\Reservation\Reservation;
use BookiFlex\Extensions\Payment\Repository\PaymentAllocationRepository;

defined( 'ABSPATH' ) || exit;

class PaymentAllocationProvider implements PaymentAllocationProviderInterface
{
    public function __construct(
        private readonly PaymentAllocationRepository $paymentAllocationRepository,
    ) {
    }

    /**
     * @param Reservation[] $reservations
     * @return array|PaymentAllocationInterface[]
     */
    public function getPaymentAllocations(array $reservations): array
    {
        $ids = array_map((fn (Reservation $reservation) => $reservation->getId()), $reservations);
        return $this->paymentAllocationRepository->findAll([
            'reservation_id' => ['in' => $ids]
        ]);
    }
}
