<?php
namespace Modules\GlobalApplication\Repository;

use Helpers\Session\ParseBase1;

class FactureRepo
{
    /** @phpstan-ignore-next-line */
    private $pdo;
    
    public function __construct(\PDO $pdo)
    {
        $this->pdo = $pdo;
    }

    // TODO : move somewhere else related to the Client
    // TODO : store result in a real cache ?

    /**
     * @var mixed
     */
    private static $hasSpeStreamImageFactureCache = null;
    /**
     * @return mixed
     */
    public static function hasSpeStreamImageFacture()
    {
        // Case : get from cache
        if (self::$hasSpeStreamImageFactureCache === null) {
            $clientPaddedNum = str_pad($_SESSION['Session_NumClient'], 4, '0', STR_PAD_LEFT);
            $fileSpe = (new ParseBase1())->getRep()->etc.'eci_spe/spe'.$clientPaddedNum.'.eci';
            if (!file_exists($fileSpe)) {
                return false;
            }
            $parametrage = file_get_contents($fileSpe, true);
            self::$hasSpeStreamImageFactureCache = (strpos((string) $parametrage, 'SPE_STREAM_IMAGE_FACTURE') !== false);
        }
        return self::$hasSpeStreamImageFactureCache;
    }
}
