<?php

declare(strict_types=1);

use App\Services\Leave\LeaveDaysCalculator;
use Carbon\Carbon;

beforeEach(function (): void {
    $this->calculator = new LeaveDaysCalculator;
});

it('calculates inclusive calendar days between two dates', function (): void {
    config(['hr.leave_calculation' => 'calendar']);

    $days = $this->calculator->between(
        Carbon::parse('2025-01-06'),
        Carbon::parse('2025-01-12'),
    );

    expect($days)->toBe(7);
});

it('calculates business days excluding weekends', function (): void {
    config(['hr.leave_calculation' => 'business']);

    $days = $this->calculator->between(
        Carbon::parse('2025-01-06'),
        Carbon::parse('2025-01-12'),
    );

    expect($days)->toBe(5);
});

it('returns zero when the end date is before the start date', function (): void {
    config(['hr.leave_calculation' => 'calendar']);

    $days = $this->calculator->between(
        Carbon::parse('2025-01-10'),
        Carbon::parse('2025-01-06'),
    );

    expect($days)->toBe(0);
});

it('counts a single day when start and end are the same', function (): void {
    config(['hr.leave_calculation' => 'calendar']);

    $days = $this->calculator->between(
        Carbon::parse('2025-01-06'),
        Carbon::parse('2025-01-06'),
    );

    expect($days)->toBe(1);
});
