1<?php
2/**
3 * This file is part of the Tmdb PHP API created by Michael Roterman.
4 *
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
7 *
8 * @package Tmdb
9 * @author Michael Roterman <michael@wtfz.net>
10 * @copyright (c) 2013, Michael Roterman
11 * @version 0.0.1
12 */
13namespace Tmdb\Repository;
14
15use Tmdb\Factory\GenreFactory;
16use Tmdb\Factory\MovieFactory;
17use Tmdb\Model\Common\GenericCollection;
18use Tmdb\Model\Genre;
19
20/**
21 * Class GenreRepository
22 * @package Tmdb\Repository
23 * @see http://docs.themoviedb.apiary.io/#genres
24 */
25class GenreRepository extends AbstractRepository
26{
27    /**
28     * Load a genre with the given identifier
29     *
30     * @param $id
31     * @param  array $parameters
32     * @param  array $headers
33     * @return Genre
34     */
35    public function load($id, array $parameters = [], array $headers = [])
36    {
37        return $this->loadCollection($parameters, $headers)->filterId($id);
38    }
39
40    /**
41     * Get the list of genres.
42     *
43     * @param  array             $parameters
44     * @param  array             $headers
45     * @return GenericCollection
46     */
47    public function loadCollection(array $parameters = [], array $headers = [])
48    {
49        return $this->createCollection(
50            $this->getApi()->getGenres($parameters, $headers)
51        );
52    }
53
54    /**
55     * Get the list of movie genres.
56     *
57     * @param  array             $parameters
58     * @param  array             $headers
59     * @return GenericCollection
60     */
61    public function loadMovieCollection(array $parameters = [], array $headers = [])
62    {
63        return $this->createCollection(
64            $this->getApi()->getMovieGenres($parameters, $headers)
65        );
66    }
67
68    /**
69     * Get the list of tv genres.
70     *
71     * @param  array             $parameters
72     * @param  array             $headers
73     * @return GenericCollection
74     */
75    public function loadTvCollection(array $parameters = [], array $headers = [])
76    {
77        return $this->createCollection(
78            $this->getApi()->getTvGenres($parameters, $headers)
79        );
80    }
81
82    /**
83     * Get the list of movies for a particular genre by id.
84     * By default, only movies with 10 or more votes are included.
85     *
86     * @param $id
87     * @param  array   $parameters
88     * @return Genre[]
89     * @param  array   $headers
90     */
91    public function getMovies($id, array $parameters = [], array $headers = [])
92    {
93        return $this->getMovieFactory()->createResultCollection($this->getApi()->getMovies($id, $parameters, $headers));
94    }
95
96    /**
97     * Create an collection of an array
98     *
99     * @param $data
100     * @return \Tmdb\Model\Collection\Genres
101     */
102    private function createCollection($data)
103    {
104        return $this->getFactory()->createCollection($data);
105    }
106
107    /**
108     * Return the related API class
109     *
110     * @return \Tmdb\Api\Genres
111     */
112    public function getApi()
113    {
114        return $this->getClient()->getGenresApi();
115    }
116
117    /**
118     * @return GenreFactory
119     */
120    public function getFactory()
121    {
122        return new GenreFactory($this->getClient()->getHttpClient());
123    }
124
125    /**
126     * @return GenreFactory
127     */
128    public function getMovieFactory()
129    {
130        return new MovieFactory($this->getClient()->getHttpClient());
131    }
132}
133