<?php

namespace Helpers\User;

class User implements UserInterface
{
        
    /**
     * objectSource
     *
     * @var mixed
     */
    private $objectSource;

    public function __construct()
    {
        $this->objectSource = $_SESSION;
    }

    /**
     * Summary of user
     * @return User
     */
    public static function getUser()
    {
        return new User;
    }
    
    /**
     * initObjectSource
     *
     * @param  mixed $objectSource
     * @return self
     */
    public function initObjectSource($objectSource) : self
    {
        $this->objectSource = $objectSource;
        return $this;
    }

    public function getCodeUser():string
    {
        return $this->objectSource['Session_Login']??'';
    }

    public function getIdUserPanier():int
    {
        return (int)$this->objectSource['id_user'];
    }

    public function getIdPanier():int
    {
        return (int)$this->objectSource['id_panier'];
    }

    public function getTypePanier():string
    {
        return $this->objectSource['sys_panier'];
    }

    public function getNiveauConfidentialite():int
    {
        return (int)$this->objectSource['NiveauConfidentialite'];
    }

    /**
     * @return \stdClass
     */
    public function getSociete()
    {
        return (object)[
            'code'      => $this->objectSource['Session_SocUsr'], // Session_SocUsr && Session_SocUsrProfil = same
            'libelle'   => $this->objectSource['societeUtilisateur']
        ];
    }

    public function getUserMultiSoc():bool
    {
        return (bool)$this->objectSource['Session_UsrMultiSoc'];
    }

    public function getUserPluriSoc():bool
    {
        return (bool)$this->objectSource['Session_UsrPluriSoc'];
    }

    public function getSupHierarchique():bool
    {
        return (bool)$this->objectSource['SuperieurHierarchique'];
    }

    public function getUO():string
    {
        return $this->objectSource['Session_UO'];
    }

    public function getLangue():string
    {
        return $this->objectSource['Session_Langue'];
    }

    /**
     * @return array<mixed> Entity Hastutil for the current user
     */
    public function getHastutil():?array
    {
        return $this->objectSource['User']['Hastutil'] ?? null;
    }
    
    /**
     * @return \stdClass
     */
    public function getSignataire()
    {
        return (object)[
            'SIG_DA'            => (bool)$this->objectSource['SIG_DA'],
            'SIG_CDE'           => (bool)$this->objectSource['SIG_CDE'],
            'SIG_BAP'           => (bool)$this->objectSource['SIG_BAP'],
            'SIG_REF'           => (bool)$this->objectSource['SIG_REF'],
            'SIG_DELEGATION'    => (bool)$this->objectSource['SIG_DELEGATION']
        ];
    }

    /**
     * @return \stdClass
     */
    public function getAdmin()
    {
        return (object) [
            'AdmLocal'      => (bool)$this->objectSource['AdmLocal'],
            'AdmCentral'    => (bool)$this->objectSource['AdmCentral'],
        ];
    }

    /**
     * @return \stdClass
     */
    public function getAuthLigne()
    {
        return (object)[
            'generique' => (bool)$this->objectSource['GLOB_AuthLigneGenerique'],
            'sFamille'  => (bool)$this->objectSource['GLOB_AuthLigneSFamille'],
            'manuelle'  => (bool)$this->objectSource['GLOB_AuthLigneManuelle'], //GLOB_AuthLigneManuelle && AuthLigneManuelle = same
            'libre'     => (bool)$this->objectSource['GLOB_AuthLigneLibre'],
        ];
    }

    /**
     * @return \stdClass
     */
    public function getImputation()
    {
        return (object) [
            'SI'    => $this->objectSource['Session_SectionImputation'], // Session_SectionImputation
            'CDC'   => $this->objectSource['Session_CDC'],
            'SCA'   => $this->objectSource['Session_SCA'],

            'LIB_SI'   => $this->objectSource['Session_LibSectionImputation'],
        ];
    }

    /**
     * @return \stdClass
     */
    public function getCentre()
    {
        return (object) [
            'livraison' => $this->objectSource['Session_CodeCtrLivraison'],
            'emetteur'  => $this->objectSource['Session_CodeCtrEmetteur'],
            'stock'     => $this->objectSource['SiteStock'],
        ];
    }

    public function getGrpSoc():string
    {
        return $this->objectSource['Session_GrpUsr'];
    }

    /**
     * Summary of getPanier
     * @return ?array<mixed>
     */
    public function getPanier(): ?array
    {
        return $this->objectSource['panier'];
    }
}
