<?php

declare(strict_types=1);

use App\Framework\DateTime\DateTimeFormatter;

beforeEach(function () {
    $this->sampleDate = new \DateTimeImmutable('2021-01-01 12:34:56', new \DateTimeZone('UTC'));
    $this->formatter = new DateTimeFormatter('UTC'); // Explicitly use UTC
});

test('format iso8601 returns correct format', function () {
    $formatted = $this->formatter->formatIso8601($this->sampleDate);

    expect($formatted)->toBe('2021-01-01T12:34:56+00:00');
});

test('format sql returns correct format', function () {
    $formatted = $this->formatter->formatSql($this->sampleDate);

    expect($formatted)->toBe('2021-01-01 12:34:56');
});

test('format date returns correct format', function () {
    $formatted = $this->formatter->formatDate($this->sampleDate);

    // The formatter uses German date format d.m.Y
    expect($formatted)->toBe('01.01.2021');
});

test('format time returns correct format', function () {
    $formatted = $this->formatter->formatTime($this->sampleDate);

    expect($formatted)->toBe('12:34:56');
});

test('custom format works correctly', function () {
    $formatted = $this->formatter->format($this->sampleDate, 'd.m.Y H:i');

    expect($formatted)->toBe('01.01.2021 12:34');
});

test('custom timezone conversion works', function () {
    $formatter = new DateTimeFormatter('Europe/Berlin');
    $formatted = $formatter->format($this->sampleDate, 'Y-m-d H:i:s T');

    // UTC 12:34:56 should be 13:34:56 in Berlin during winter time
    expect($formatted)->toBe('2021-01-01 13:34:56 CET');
});

test('datetime object works correctly', function () {
    $dateTime = new \DateTime('2021-01-01 12:34:56', new \DateTimeZone('UTC'));
    $formatted = $this->formatter->formatIso8601($dateTime);

    expect($formatted)->toBe('2021-01-01T12:34:56+00:00');
});
