<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
use Chadicus\Marvel\Api\Client;
use Chadicus\Marvel\Api\Entities\Character;
$publicApiKey = getenv('PUBLIC_KEY');
$privateApiKey = getenv('PRIVATE_KEY');
$client = new Client($privateApiKey, $publicApiKey);
//24 is the id of Bendis.  312 is the id of Deodato
$characters = Character::findAll($client, ['name' => 'spider-man']);
foreach ($characters as $character) {
    echo $character->getName() . PHP_EOL;
    foreach ($character->getUrls() as $url) {
        echo "\t{$url->getType()}\n";
    }
    echo "{$character->getEvents()->getAvailable()} events available\n";
    echo "Here are the first {$character->getEvents()->getReturned()}\n";
    foreach ($character->getEvents()->getItems() as $item) {
        echo "\t{$item['name']}\n";
    }
    echo "{$character->getSeries()->getAvailable()} series available\n";
    echo "Here are the first {$character->getSeries()->getReturned()}\n";
    foreach ($character->getSeries()->getItems() as $item) {
        echo "\t{$item['name']}\n";
    }
}
 /**
  * Verify query parameters are set properly with findAll().
  *
  * @test
  * @covers ::findAll
  *
  * @return void
  */
 public function findAllParametersSetProperly()
 {
     $now = new \DateTime();
     $criteria = ['name' => 'a name', 'modifiedSince' => $now->format('r'), 'comics' => [1, 2, 3], 'series' => [2, 4, 6], 'events' => [1, 3, 5], 'stories' => [7, 8, 9], 'orderBy' => 'name'];
     $adapter = new CharacterAdapter();
     $client = new Client('not under test', 'not under test', $adapter);
     $characters = Character::findAll($client, $criteria);
     $characters->next();
     $expectedParameters = ['name' => 'a name', 'modifiedSince' => $now->format('c'), 'comics' => '1,2,3', 'series' => '2,4,6', 'events' => '1,3,5', 'stories' => '7,8,9', 'orderBy' => 'name'];
     foreach ($expectedParameters as $key => $value) {
         $this->assertSame($value, $adapter->parameters[$key]);
     }
 }