<?php
namespace Claromentis\Search;

$GLOBALS["__65da1b1ec2" . "d6653e8a0ab7" . "848e536215"] = (@$GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"] ?: array()) + array("_63fc7fd38817bf222bc4e3a0" . "4e17f2c3" => base64_decode("Ii4gTWVzc2FnZT" . "ogIg=="), "_4d707fab93" . "bebb00bbe69" . "e8159697c90" => base64_decode(""), "_89317315bf1853e" . "3644635cf16af3b0" . "6" => base64_decode("VGV4dCBleHRy" . "YWN0b3IgZXJy" . "b3IgZnJvbSBm" . "aWxlICI="), "_76b8f4f0c6d" . "86cb513c6a0c" . "491de1e8d" => base64_decode("VGV4dCBleHRyYWN0b3IgaXMgY29uZmlndXJlZCBidXQgdGhlIGNvbm5lY3Rpb24gY2h" . "lY2sgZmFpbGVkIHNvIGl0IHdpbGwgYmUgZGlzYWJsZWQuIE1lc3NhZ2U6ICI="), "_e92ad74" . "2fc12ec1" . "dd5c3055" . "7fafca33" . "1" => base64_decode("Ig" . "=="));
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Vaites\ApacheTika;
class TextExtractorService implements LoggerAwareInterface
{
    use LoggerAwareTrait;
    protected ?ApacheTika\Client $tikaClient = null;
    protected ?bool $isWorking = null;
    public function __construct(?ApacheTika\Client $_7ea853d2916986a25d9e854d8839f86e = null, LoggerInterface $logger = null)
    {
        $this->setLogger($logger ?? new NullLogger());
        $this->tikaClient = $_7ea853d2916986a25d9e854d8839f86e;
    }
    
    
    
    
    
    public function getText(string $filename) : string
    {
        if ($this->tikaClient === null || !$this->isAvailable()) {
            return $GLOBALS["__65da1b1ec2d6653" . "e8a0ab7848e536215"]["_4d707fa" . "b93bebb0" . "0bbe69e8" . "159697c9" . "0"];
        }
        try {
            return $this->tikaClient->getText($filename);
        } catch (\Exception $e) {
            $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab78" . "48e536215"]["_89317315bf1853e" . "3644635cf16af3b0" . "6"] . $filename . $GLOBALS["__65da1b1ec2d6653e8a0ab784" . "8e536215"]["_63fc7fd38817bf222bc" . "4e3a04e17f2c3"] . $e->getMessage() . $GLOBALS["__65da1b1ec2d6653e8" . "a0ab7848e536215"]["_e92ad74" . "2fc12ec1" . "dd5c3055" . "7fafca33" . "1"]);
            $this->logger->debug($e);
            return $GLOBALS["__65da1b1ec2d6653e8a0ab7848" . "e536215"]["_4d707fab93bebb00bbe69e8" . "159697c90"];
        }
    }
    public function isAvailable() : bool
    {
        if ($this->isWorking === null) {
            $this->isWorking = false;
            if ($this->tikaClient !== null) {
                try {
                    $this->tikaClient->check();
                    $this->isWorking = true;
                } catch (\Exception $e) {
                    $this->logger->error($GLOBALS["__65da1b1ec2d6653e8a0ab7848e" . "536215"]["_76b8f4f0c6d86cb513c6a0c491de1e" . "8d"] . $e->getMessage() . $GLOBALS["__65da1b1ec2d6653e8a0ab" . "7848e536215"]["_e92ad742fc12ec1dd5c30557fafca3" . "31"]);
                    $this->logger->debug($e);
                }
            }
        }
        return $this->isWorking;
    }
}