<?php

namespace Modules\Additional\Specifique\Client30\API\SharePoint;

use Helpers\Fichier\Fichier;
use Helpers\Session\ParseBase1;

class SharePoint
{

   
    protected $urlApi;
    protected $client;
    protected $data;
    protected $token;
    protected $code;
    protected $header;
    protected $XFUNCTIONSKEY;
    protected $codeAPI;
    protected $proxy;
    protected $proxyPort;

    use \Modules\Additional\Specifique\Client30\API\SharePoint\Traits\DA;
    use \Modules\Additional\Specifique\Client30\API\SharePoint\Traits\AO;
    use \Modules\Additional\Specifique\Client30\API\SharePoint\Traits\OP;
    use \Modules\Additional\Specifique\Client30\API\SharePoint\Traits\CDE;
    use \Modules\Additional\Specifique\Client30\API\SharePoint\Traits\AVN;


    public function __construct($pdo)
    {
        $this->codeAPI = 'SOGEA_AI3';
        $dilispec = new \Entity\Model\Dilispec($pdo);
        $dilispec = $dilispec->findAll(['TYPEDICO' => $this->codeAPI]);

        foreach ($dilispec as $param) {
            ${str_replace('-', '', $param['CODEDICO'])} = $param['LIB01DICO'];
        }

        // @phpstan-ignore-next-line
        $this->XFUNCTIONSKEY = $XFUNCTIONSKEY;

        $parametrage = Fichier::fileGetContents((new ParseBase1())->getRep()->etc.'api/externe/'.$this->codeAPI.'/Parametres.json', true);
        $parametrage = json_decode($parametrage, true);

        // @phpstan-ignore-next-line
        $this->setUrlApi($parametrage[$TYPE_ENVIRONNEMENT]['BaseUrl']);

        // @phpstan-ignore-next-line
        $this->proxy = ($parametrage[$TYPE_ENVIRONNEMENT]['proxy'] ?? '');

        // @phpstan-ignore-next-line
        $this->proxyPort = ($parametrage[$TYPE_ENVIRONNEMENT]['proxyPort'] ?? '');

        $this->client = new \GuzzleHttp\Client();

        return true;
    }

    public function setUrlApi($url)
    {
        $this->urlApi = $url;
    }

    public function setData($data)
    {
        return $this->data = $data;
    }

    public function setToken($token)
    {
        $this->token = $token;
    }

    public function getCode()
    {
        return $this->code;
    }

    public function getHeader()
    {
        return $this->header;
    }
}
