<?php

namespace Tests\Unit;

use App\Services\ZatcaPhase1QrService;
use PHPUnit\Framework\TestCase;

class ZatcaPhase1QrServiceTest extends TestCase
{
    public function test_phase_one_tlv_contains_the_five_required_tags(): void
    {
        $encoded = ZatcaPhase1QrService::generateTlvBase64(
            'MUTLAQ SALEH SATI',
            '302176698800003',
            '2026-08-11T10:15:00+03:00',
            '115.00',
            '15.00'
        );

        $payload = base64_decode($encoded, true);
        $tags = [];
        for ($offset = 0, $length = strlen($payload); $offset < $length;) {
            $tag = ord($payload[$offset++]);
            $valueLength = ord($payload[$offset++]);
            $tags[$tag] = substr($payload, $offset, $valueLength);
            $offset += $valueLength;
        }

        $this->assertSame('MUTLAQ SALEH SATI', $tags[1]);
        $this->assertSame('302176698800003', $tags[2]);
        $this->assertSame('2026-08-11T10:15:00+03:00', $tags[3]);
        $this->assertSame('115.00', $tags[4]);
        $this->assertSame('15.00', $tags[5]);
    }
}
