<?php

namespace API\Hiveo\Traits;

trait Reminds
{
    
    
   
    public function manualReminds($siren, $all = false)
    {
        try {
            if (!$all) {
                $body =  json_encode([
                    'depositors' => ['FR-'.$siren]
                ]);
            } else {
                $body ='{}';
            }

            $response = $this->client->post($this->urlApi.'api/collectors/'.$this->siretDemandeur.'/manual-reminds', [
        
                'headers' => [
                    'Authorization' => 'Bearer '. $this->token,
                    'Content-Type' => 'application/json',
                ],'body' => $body]);

            $this->code = $response->getStatusCode();
            $this->header = $response->getHeaderLine('content-type');
            
            $this->setData(json_decode($response->getBody()->getContents(), true));

            return $this->data ?? $this->code;
        } catch (\GuzzleHttp\Exception\RequestException $e) {
            $returnLog='date : '.date("Y-m-d H:i:s").'
            url : '.$this->urlApi.'api/collectors/'.$this->siretDemandeur.'/manual-reminds'.'

            code : '.$e->getResponse()->getStatusCode().'

            body envoyé : '.$body.'

            Api erreur: ' . $e->getResponse()->getBody()->getContents();
            \Helpers\Fichier\Fichier::createFichierTmp('Log_Hiveo_manual_reminds.txt', $returnLog);
            return [];
        }
    }
}
