<?php

namespace App\Helpers;

use Endroid\QrCode\QrCode;
use Endroid\QrCode\Writer\PngWriter;

class QRCodeHelper
{
    public static function generate(string $data, int $size = 200): string
    {
        $qrCode = new QrCode(
            data: $data,
            size: $size,
            margin: 10
        );

        $writer = new PngWriter();
        $result = $writer->write($qrCode);

        return $result->getDataUri();
    }

    public static function generateDataUrl(string $invoiceNumber, float $amount, string $date): string
    {
        $data = json_encode([
            'inv' => $invoiceNumber,
            'amt' => $amount,
            'dt' => $date,
        ]);

        return self::generate($data);
    }
}
