<?php

app_require('modules/selfserve/traits/selfserve_lane_invoice_t.php');

use modules\selfserve\traits\selfserve_lane_invoice_t;

class SelfserveLaneInvoiceIncludedMinutesHarness
{
    use selfserve_lane_invoice_t;

    public function elapsedMinutesForBilling(?int $elapsed_wash_time_seconds): int
    {
        return $this->calculateElapsedMinutesForBilling($elapsed_wash_time_seconds);
    }

    public function billableMinutesForBilling(int $elapsed_minutes, int $included_minutes): int
    {
        return $this->calculateBillableMinutes($elapsed_minutes, $included_minutes);
    }
}

it('computes billable minutes when elapsed minutes exceed included minutes', function (): void {
    $harness = new SelfserveLaneInvoiceIncludedMinutesHarness();

    $elapsed_minutes = $harness->elapsedMinutesForBilling(181); // ceil(3.016...) = 4
    $billable_minutes = $harness->billableMinutesForBilling($elapsed_minutes, 2);

    expect($elapsed_minutes)->toBe(4);
    expect($billable_minutes)->toBe(2);
});

it('computes zero billable minutes when elapsed minutes equal included minutes', function (): void {
    $harness = new SelfserveLaneInvoiceIncludedMinutesHarness();

    $elapsed_minutes = $harness->elapsedMinutesForBilling(120);
    $billable_minutes = $harness->billableMinutesForBilling($elapsed_minutes, 2);

    expect($elapsed_minutes)->toBe(2);
    expect($billable_minutes)->toBe(0);
});

it('computes zero billable minutes when included minutes exceed elapsed minutes', function (): void {
    $harness = new SelfserveLaneInvoiceIncludedMinutesHarness();

    $elapsed_minutes = $harness->elapsedMinutesForBilling(59);
    $billable_minutes = $harness->billableMinutesForBilling($elapsed_minutes, 5);

    expect($elapsed_minutes)->toBe(1);
    expect($billable_minutes)->toBe(0);
});

it('handles zero and low elapsed wash time edge cases', function (): void {
    $harness = new SelfserveLaneInvoiceIncludedMinutesHarness();

    expect($harness->elapsedMinutesForBilling(null))->toBe(0);
    expect($harness->elapsedMinutesForBilling(0))->toBe(0);
    expect($harness->elapsedMinutesForBilling(1))->toBe(1);
    expect($harness->billableMinutesForBilling(0, 20))->toBe(0);
    expect($harness->billableMinutesForBilling(1, 20))->toBe(0);
});
