<?php

declare(strict_types=1);

namespace App\Tests\Service\Exercise;

use App\Service\Exercise\ExerciseYearResolver;
use DateTimeImmutable;
use PHPUnit\Framework\TestCase;

/**
 * @internal
 */
final class ExerciseYearResolverTest extends TestCase
{
    public function testNonForfaitJuneMapsToNextYear(): void
    {
        $resolver = new ExerciseYearResolver();

        self::assertSame(2026, $resolver->forDate(new DateTimeImmutable('2025-06-01')));
        self::assertSame(2026, $resolver->forDate(new DateTimeImmutable('2025-06-30')));
    }

    public function testNonForfaitMayMapsToSameYear(): void
    {
        $resolver = new ExerciseYearResolver();

        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-05-01')));
        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-05-31')));
    }

    public function testNonForfaitDecemberMapsToNextYear(): void
    {
        $resolver = new ExerciseYearResolver();

        self::assertSame(2026, $resolver->forDate(new DateTimeImmutable('2025-12-31')));
    }

    public function testNonForfaitJanuaryMapsToSameYear(): void
    {
        $resolver = new ExerciseYearResolver();

        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-01-15')));
    }

    public function testForfaitReturnsCalendarYearRegardlessOfMonth(): void
    {
        $resolver = new ExerciseYearResolver();

        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-01-15'), true));
        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-06-01'), true));
        self::assertSame(2025, $resolver->forDate(new DateTimeImmutable('2025-12-31'), true));
    }

    public function testForfaitFlagDefaultsToFalse(): void
    {
        $resolver = new ExerciseYearResolver();

        // June without explicit flag must follow non-forfait rule (year + 1).
        self::assertSame(2026, $resolver->forDate(new DateTimeImmutable('2025-06-01')));
    }
}
