<?php

declare (strict_types=1);
namespace Freefactu_Vendor\Endroid\QrCode\Writer;

use Freefactu_Vendor\Endroid\QrCode\Label\LabelInterface;
use Freefactu_Vendor\Endroid\QrCode\Logo\LogoInterface;
use Freefactu_Vendor\Endroid\QrCode\QrCodeInterface;
use Freefactu_Vendor\Endroid\QrCode\Writer\Result\GdResult;
use Freefactu_Vendor\Endroid\QrCode\Writer\Result\ResultInterface;
use Freefactu_Vendor\Endroid\QrCode\Writer\Result\WebPResult;
final class WebPWriter extends AbstractGdWriter
{
    public const WRITER_OPTION_QUALITY = 'quality';
    public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?LabelInterface $label = null, array $options = []): ResultInterface
    {
        if (!isset($options[self::WRITER_OPTION_QUALITY])) {
            $options[self::WRITER_OPTION_QUALITY] = -1;
        }
        /** @var GdResult $gdResult */
        $gdResult = parent::write($qrCode, $logo, $label, $options);
        return new WebPResult($gdResult->getMatrix(), $gdResult->getImage(), $options[self::WRITER_OPTION_QUALITY]);
    }
}
