<?php

declare(strict_types=1);

namespace App\Tests\Service\WorkHours;

use App\Entity\Absence;
use App\Enum\HalfDay;
use App\Service\WorkHours\AbsenceSegmentsResolver;
use DateTime;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 */
final class AbsenceSegmentsResolverTest extends TestCase
{
    public function testResolveForSameDayMorningOnly(): void
    {
        $absence = new Absence()
            ->setStartDate(new DateTime('2026-02-16'))
            ->setEndDate(new DateTime('2026-02-16'))
            ->setStartHalf(HalfDay::AM)
            ->setEndHalf(HalfDay::AM)
        ;

        $resolver = new AbsenceSegmentsResolver();

        self::assertSame([true, false], $resolver->resolveForDate($absence, '2026-02-16'));
    }

    public function testResolveForSameDayAfternoonOnly(): void
    {
        $absence = new Absence()
            ->setStartDate(new DateTime('2026-02-16'))
            ->setEndDate(new DateTime('2026-02-16'))
            ->setStartHalf(HalfDay::PM)
            ->setEndHalf(HalfDay::PM)
        ;

        $resolver = new AbsenceSegmentsResolver();

        self::assertSame([false, true], $resolver->resolveForDate($absence, '2026-02-16'));
    }

    public function testResolveForMultiDayBoundaries(): void
    {
        $absence = new Absence()
            ->setStartDate(new DateTime('2026-02-16'))
            ->setEndDate(new DateTime('2026-02-18'))
            ->setStartHalf(HalfDay::PM)
            ->setEndHalf(HalfDay::AM)
        ;

        $resolver = new AbsenceSegmentsResolver();

        self::assertSame([false, true], $resolver->resolveForDate($absence, '2026-02-16'));
        self::assertSame([true, true], $resolver->resolveForDate($absence, '2026-02-17'));
        self::assertSame([true, false], $resolver->resolveForDate($absence, '2026-02-18'));
    }
}
