<?php

namespace Api\PhpServices\ShopImage;

use Endroid\QrCode\ErrorCorrectionLevel;
use Endroid\QrCode\QrCode;

class QR
{
    private $_content;
    private $_size = 300;
    private $_logo_url = '';
    private $_logo_size = 80;
    private $_writeFile = false;
    private $_blockSize = QrCode::ROUND_BLOCK_SIZE_MODE_MARGIN;
//    private $_errorCorrectionLevel;

 
    public function setRoundBlockSize($_blockSize)
    {
        $this->_blockSize = $_blockSize;
    }


    public function setWriteFile(bool $writeFile): void
    {
        $this->_writeFile = $writeFile;
    }

    public function setContent($content): void
    {
        $this->_content = $content;
    }

    public function setSize(int $size): void
    {
        $this->_size = $size;
    }

    public function setLogoUrl(string $logo_url): void
    {
        $this->_logo_url = $logo_url;
    }

    public function setLogoSize(int $logo_size): void
    {
        $this->_logo_size = $logo_size;
    }

    public function __construct($content)
    {
        $this->_content = $content;
    }

    public function get(){
        $qr = new QrCode($this->_content);
        $qr->setSize($this->_size);
        $qr->setRoundBlockSize(true, $this->_blockSize);

        if(!empty($this->_logo_url)){
            $qr->setLogoPath($this->_logo_url);
            $qr->setLogoSize($this->_logo_size);
        }

        if (!$this->_writeFile) {
            header('Content-Type: ' . $qr->getContentType());
        }
        return $qr->writeString();
    }

}