<?php

declare(strict_types=1);

use routes\productsRoute;

function products_route_customer_booking_department_pricing_allowed(
    bool $isCustomerBookingSession,
    bool $useFinalPrice,
    ?int $customerId,
    bool $isOwnCustomer = true
): bool {
    $route = new class ($isOwnCustomer) extends productsRoute {
        public function __construct(private readonly bool $isOwnCustomer)
        {
            parent::__construct();
        }

        public function isOwnCustomerContext(int $targetCustomerNumber): bool
        {
            return $this->isOwnCustomer;
        }
    };

    $method = new ReflectionMethod(productsRoute::class, 'canUseCustomerBookingDepartmentPricing');

    return (bool)$method->invoke($route, $isCustomerBookingSession, $useFinalPrice, $customerId);
}

it('allows customer booking final department pricing for the authenticated customer', function (): void {
    expect(products_route_customer_booking_department_pricing_allowed(true, true, 35131752, true))
        ->toBeTrue();
});

it('allows customer booking final department pricing when no customer id is requested', function (): void {
    expect(products_route_customer_booking_department_pricing_allowed(true, true, null))
        ->toBeTrue();
});

it('does not allow customer booking department pricing for another customer', function (): void {
    expect(products_route_customer_booking_department_pricing_allowed(true, true, 35131752, false))
        ->toBeFalse();
});

it('does not bypass department access outside final price booking reads', function (): void {
    expect(products_route_customer_booking_department_pricing_allowed(true, false, 35131752, true))
        ->toBeFalse()
        ->and(products_route_customer_booking_department_pricing_allowed(false, true, 35131752, true))
        ->toBeFalse();
});
