<?php

namespace Helpers\SSO;

use Entity\Model\Paravrac;

class SSO
{
    private \Skeleton\Router $router;
    private \Psr\Container\ContainerInterface $contenaire;
    private \PDO $pdo;
    
    /**
     * __construct
     *
     * @param  \Skeleton\Router $router
     * @param  \Psr\Container\ContainerInterface $contenaire
     * @param  \PDO $pdo
     * @return void
     */
    public function __construct(\Skeleton\Router $router, \Psr\Container\ContainerInterface $contenaire, \PDO $pdo)
    {
        $this->router = $router;
        $this->contenaire = $contenaire;
        $this->pdo = $pdo;
    }
    
    /**
     * getInfoSSO
     *
     * @return array<mixed>
     */
    public function getInfoSSO() : array
    {
        $ssoActiv = 0;
        $typeSso = '';
        $lienSSO = '';
        $paravrac = new Paravrac($this->pdo);
        
        if (($paravrac->find(['CODEPARV' => 'CNX_SSO', 'TYPEPARV' => 'PARAMGEN'])['LIB01PARV']) =='O') {
            $ssoActiv = 1;
            
            $typeSso = $paravrac->find(['CODEPARV' => 'TYPE_SSO', 'TYPEPARV' => 'PARAMGEN'])['LIB01PARV'] ?? '';

            if ($typeSso == 'ADFS') {
                $lienSSO = $this->router->generateUri('Index.ADFS.ADFS');
            } else {
                $lienSSO = $this->contenaire->get('urlOxaprocSso').'/index.php';
            }
        }

        return [
            'ssoActiv' => $ssoActiv,
            'typeSso' => $typeSso,
            'lienSSO' => $lienSSO

        ];
    }
}
