<?php

use App\Services\DateNormalizer;

it('normalizes common European and ISO date formats to Y-m-d', function () {
    expect(DateNormalizer::toDate('30.10.2025'))->toBe('2025-10-30');
    expect(DateNormalizer::toDate('30/10/2025'))->toBe('2025-10-30');
    expect(DateNormalizer::toDate('30-10-2025'))->toBe('2025-10-30');
    expect(DateNormalizer::toDate('1/2/25'))->toBe('2025-02-01');
    expect(DateNormalizer::toDate('2025-10-30'))->toBe('2025-10-30');
    expect(DateNormalizer::toDate('2025/10/30'))->toBe('2025-10-30');
    expect(DateNormalizer::toDate('  30.10.2025  '))->toBe('2025-10-30');
});

it('returns null for empty or invalid dates', function () {
    expect(DateNormalizer::toDate(null))->toBeNull();
    expect(DateNormalizer::toDate(''))->toBeNull();
    expect(DateNormalizer::toDate('not-a-date'))->toBeNull();
    // invalid calendar date
    expect(DateNormalizer::toDate('32.01.2025'))->toBeNull();
});
