<?php

namespace App\Services;

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

class QRCodeService
{
    public function generate(string $data, int $size = 300): string
    {
        $builder = new Builder(
            writer: new PngWriter(),
            size: $size,
            margin: 10,
            data: $data
        );
        $result = $builder->build();

        return 'data:image/png;base64,' . base64_encode($result->getString());
    }

    public function generateBase64(string $data): string
    {
        return $this->generate($data);
    }

    public function generateDataUrl(string $trackingCode): string
    {
        $data = sprintf('%s|%s|%s',
            'SABOK-TRACKING',
            $trackingCode,
            now()->format('Y-m-d H:i:s')
        );

        return $this->generate($data);
    }
}
