1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 
<?php declare(strict_types = 1);
/**
 * This file is part of the Tmdb package.
 *
 * (c) Vincent Faliès <vincent@vfac.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @author Vincent Faliès <vincent@vfac.fr>
 * @copyright Copyright (c) 2017
 */

namespace VfacTmdb\Items;

use VfacTmdb\Abstracts\Item;
use VfacTmdb\Interfaces\Items\PeopleInterface;
use VfacTmdb\Traits\ElementTrait;
use VfacTmdb\Exceptions\TmdbException;
use VfacTmdb\Interfaces\TmdbInterface;
use VfacTmdb\Items\PeopleMovieCredit;
use VfacTmdb\Items\PeopleTVShowCredit;
use VfacTmdb\Results;

/**
 * People class
 * @package Tmdb
 * @author Vincent Faliès <vincent@vfac.fr>
 * @copyright Copyright (c) 2017
 */
class People extends Item implements PeopleInterface
{
    use ElementTrait;

    /**
     * Constructor
     * @param TmdbInterface $tmdb
     * @param int $people_id
     * @param array $options
     * @throws TmdbException
     */
    public function __construct(TmdbInterface $tmdb, int $people_id, array $options = array())
    {
        parent::__construct($tmdb, $people_id, $options, 'person');

        $this->setElementTrait($this->data);
    }

    /**
     * Adult
     * @return bool
     */
    public function getAdult() : bool
    {
        if (isset($this->data->adult)) {
            return $this->data->adult;
        }
        return false;
    }

    /**
     * Alse Known as
     * @return array
     */
    public function getAlsoKnownAs() : array
    {
        if (isset($this->data->also_known_as)) {
            return $this->data->also_known_as;
        }
        return [];
    }

    /**
     * Biography
     * @return string
     */
    public function getBiography() : string
    {
        if (isset($this->data->biography)) {
            return $this->data->biography;
        }
        return '';
    }

    /**
     * Birthday
     * @return string
     */
    public function getBirthday() : string
    {
        if (isset($this->data->birthday)) {
            return $this->data->birthday;
        }
        return '';
    }

    /**
     * Deathday
     * @return string
     */
    public function getDeathday() : string
    {
        if (isset($this->data->deathday)) {
            return $this->data->deathday;
        }
        return '';
    }

    /**
     * Gender
     * @return int
     */
    public function getGender() : int
    {
        if (isset($this->data->gender)) {
            return $this->data->gender;
        }
        return 0;
    }

    /**
     * Homepage
     * @return string
     */
    public function getHomepage() : string
    {
        if (isset($this->data->homepage)) {
            return $this->data->homepage;
        }
        return '';
    }

    /**
     * Id
     * @return int
     */
    public function getId() : int
    {
        if (isset($this->data->id)) {
            return $this->data->id;
        }
        return 0;
    }

    /**
     * Imdb Id
     * @return string
     */
    public function getImdbId() : string
    {
        if (isset($this->data->imdb_id)) {
            return $this->data->imdb_id;
        }
        return '';
    }

    /**
     * Name
     * @return string
     */
    public function getName() : string
    {
        if (isset($this->data->name)) {
            return $this->data->name;
        }
        return '';
    }

    /**
     * Place of birth
     * @return string
     */
    public function getPlaceOfBirth() : string
    {
        if (isset($this->data->place_of_birth)) {
            return $this->data->place_of_birth;
        }
        return '';
    }

    /**
     * Popularity
     * @return float
     */
    public function getPopularity() : float
    {
        if (isset($this->data->popularity)) {
            return $this->data->popularity;
        }
        return 0;
    }

    /**
     * Image profile path
     * @return string
     */
    public function getProfilePath() : string
    {
        if (isset($this->data->profile_path)) {
            return $this->data->profile_path;
        }
        return '';
    }

    /**
     * Images Profiles
     * @return \Generator|Results\Image
     */
    public function getProfiles() : \Generator
    {
        $params = [];
        $this->tmdb->checkOptionLanguage($this->params, $params);
        $data = $this->tmdb->getRequest('person/' . (int) $this->id . '/images', $params);

        foreach ($data->profiles as $b) {
            $image = new Results\Image($this->tmdb, $this->id, $b);
            yield $image;
        }
    }

    /**
     * Get movies cast
     * @return \Generator|Results\PeopleMovieCast
     */
    public function getMoviesCast() : \Generator
    {
        $credit = new PeopleMovieCredit($this->tmdb, $this->id);
        return $credit->getCast();
    }

    /**
     * Get movies crew
     * @return \Generator|Results\PeopleMovieCast
     */
    public function getMoviesCrew() : \Generator
    {
        $credit = new PeopleMovieCredit($this->tmdb, $this->id);
        return $credit->getCrew();
    }


    /**
     * Get TVShow cast
     * @return \Generator|Results\PeopleTVShowCast
     */
    public function getTVShowCast() : \Generator
    {
        $credit = new PeopleTVShowCredit($this->tmdb, $this->id);
        return $credit->getCast();
    }

    /**
     * Get TVShow crew
     * @return \Generator|Results\PeopleTVShowCast
     */
    public function getTVShowCrew() : \Generator
    {
        $credit = new PeopleTVShowCredit($this->tmdb, $this->id);
        return $credit->getCrew();
    }
}