<?php
namespace API\InfoLegale\Traits;

trait Events
{
    
            // "filters": [
            //         $eventCode,2150
            //   ],


    /**
     * @param array<string> $listeEvent
     * @return mixed
     */
    public function companiesEvents(string $siren, string $country, array $listeEvent)
    {
        $conteur  = 0;

        $body = '{
            "filters" : [';

        foreach ($listeEvent as $liste) {
            if ($conteur > 0) {
                $body .= ',';
            }
            
            $conteur++;
            
            $body .= '"$.eventCode,'.$liste.'"';
        }
                
        $body .= '        ],
        "number" : 100
                
        }';
        
        try {
            $response = $this->client->get($this->urlApi.'companies/'.$country.'/'.$siren.'/events', [
                    'headers' => [
                        'Authorization' => 'Bearer '. $this->token,
                        'Content-Type' => 'application/json',
                    ],'body' => $body]);

            $this->code = $response->getStatusCode();
            $this->header = $response->getHeaderLine('content-type');
            
            return json_decode($response->getBody()->getContents(), true);
        } catch (\Exception $e) {
            return [];
        }
    }
}
