<?php

namespace Modules\Consultation\Rules;

use Modules\Consultation\WebService\Consultation;
use Psr\Http\Message\ServerRequestInterface;

class ReferencementAO
{
    /** @var ServerRequestInterface $request */
    protected ServerRequestInterface $request;

    /** @var \PDO $pdo */
    protected \PDO $pdo;

    /** @var string|mixed $currentUser */
    protected $currentUser;

    /** @var array<mixed> $droits */
    protected array $droits;

    /** @var \Modules\Consultation\Repository\ReferencementAO $referencementAORepo */
    protected $referencementAORepo;

    /**
     * @param ServerRequestInterface $request
     * @param \PDO $pdo
     */
    public function __construct(ServerRequestInterface $request, \PDO $pdo)
    {
        $this->request              = $request;
        $this->pdo                  = $pdo;
        $this->currentUser          = $_SESSION['Session_Login'];
        $this->referencementAORepo  = new \Modules\Consultation\Repository\ReferencementAO($pdo);
    }

    /**
     * @return bool
     */
    public function popupRefusAO(): bool
    {
        $codeTrait = $this->request->getAttribute('codeTrait');

        $detailRefAO = $this->referencementAORepo->detailRefAo($codeTrait);

        if ($detailRefAO['ACCEPT_REFU'] !== '') {
            return false;
        }

        return true;
    }

    /**
     * @return bool
     */
    public function accepterReferencementAO(): bool
    {
        return $this->popupRefusAO();
    }
}
