<?php

declare(strict_types=1);

namespace App\Tests\Unit\Scolarite\Domain\Exception;

use App\Scolarite\Domain\Exception\ReglesDevoirsNonRespecteesException;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class ReglesDevoirsNonRespecteesExceptionTest extends TestCase
{
    #[Test]
    public function blockingExceptionHasBlockingMessage(): void
    {
        $exception = new ReglesDevoirsNonRespecteesException(
            warnings: [['ruleType' => 'minimum_delay', 'message' => 'msg', 'params' => []]],
            bloquant: true,
        );

        self::assertStringContainsString('Impossible de créer ce devoir', $exception->getMessage());
        self::assertStringContainsString('msg', $exception->getMessage());
        self::assertTrue($exception->bloquant);
    }

    #[Test]
    public function warningExceptionHasWarningMessage(): void
    {
        $exception = new ReglesDevoirsNonRespecteesException(
            warnings: [['ruleType' => 'minimum_delay', 'message' => 'msg', 'params' => []]],
        );

        self::assertStringContainsString('ne respecte pas', $exception->getMessage());
        self::assertFalse($exception->bloquant);
    }

    #[Test]
    public function suggestedDatesAreAccessible(): void
    {
        $dates = ['2026-03-25', '2026-03-26'];

        $exception = new ReglesDevoirsNonRespecteesException(
            warnings: [['ruleType' => 'minimum_delay', 'message' => 'msg', 'params' => []]],
            bloquant: true,
            suggestedDates: $dates,
        );

        self::assertSame($dates, $exception->suggestedDates);
    }

    #[Test]
    public function suggestedDatesDefaultToEmpty(): void
    {
        $exception = new ReglesDevoirsNonRespecteesException(
            warnings: [['ruleType' => 'minimum_delay', 'message' => 'msg', 'params' => []]],
            bloquant: true,
        );

        self::assertEmpty($exception->suggestedDates);
    }

    #[Test]
    public function warningsAreAccessible(): void
    {
        $warnings = [
            ['ruleType' => 'minimum_delay', 'message' => 'Au moins 3 jours.', 'params' => ['days' => 3]],
            ['ruleType' => 'no_monday_after', 'message' => 'Pas après vendredi.', 'params' => []],
        ];

        $exception = new ReglesDevoirsNonRespecteesException(
            warnings: $warnings,
            bloquant: true,
        );

        self::assertSame($warnings, $exception->warnings);
    }
}
