/*
 * Copyright 2012 Uwe Trottmann
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.uwetrottmann.tmdb.services;

import com.google.gson.reflect.TypeToken;
import com.uwetrottmann.tmdb.TmdbApiBuilder;
import com.uwetrottmann.tmdb.TmdbApiService;
import com.uwetrottmann.tmdb.entities.Movie;
import com.uwetrottmann.tmdb.entities.ResultsPage;
import com.uwetrottmann.tmdb.entities.Trailers;

public class MoviesService extends TmdbApiService {

    /**
     * Get the basic movie information for a specific movie id.
     * 
     * @return Builder instance.
     */
    public SummaryBuilder summary(Integer id) {
        return new SummaryBuilder(this, id);
    }

    /**
     * Get the trailers for a specific movie id.
     * 
     * @return Builder instance.
     */
    public TrailerBuilder trailers(Integer id) {
        return new TrailerBuilder(this, id);
    }

    /**
     * Get the list of popular movies on The Movie Database. This list refreshes
     * every day.
     * 
     * @return Builder instance.
     */
    public PopularBuilder popular() {
        return new PopularBuilder(this);
    }

    public static final class SummaryBuilder extends TmdbApiBuilder<Movie> {
        private static final String URI = "/movie/" + FIELD_ID + FIELD_API_KEY + FIELD_LANGUAGE;

        private SummaryBuilder(MoviesService service, Integer id) {
            super(service, new TypeToken<Movie>() {
            }, URI);

            field(FIELD_ID, id);
        }

        /**
         * Set the language. Attention: will not default to English, but instead
         * will return empty field.
         * 
         * @param languageCode ISO 639-1 code.
         */
        public SummaryBuilder language(String languageCode) {
            parameter(FIELD_LANGUAGE, languageCode);
            return this;
        }
    }

    public static final class TrailerBuilder extends TmdbApiBuilder<Trailers> {
        private static final String URI = "/movie/" + FIELD_ID + "/trailers" + FIELD_API_KEY;

        private TrailerBuilder(MoviesService service, Integer id) {
            super(service, new TypeToken<Trailers>() {
            }, URI);

            field(FIELD_ID, id);
        }
    }

    public static final class PopularBuilder extends TmdbApiBuilder<ResultsPage> {
        private static final String URI = "/movie/popular" + FIELD_API_KEY + FIELD_PAGE
                + FIELD_LANGUAGE;

        private PopularBuilder(MoviesService service) {
            super(service, new TypeToken<ResultsPage>() {
            }, URI);
        }

        private PopularBuilder(MoviesService service, int page) {
            this(service);

            parameter(FIELD_PAGE, page);
        }

        /**
         * Set the language. Attention: will not default to English, but instead
         * will return empty field.
         * 
         * @param languageCode ISO 639-1 code.
         */
        public PopularBuilder language(String languageCode) {
            parameter(FIELD_LANGUAGE, languageCode);
            return this;
        }
    }
}

@@ -1039,32 +1039,58 @@
 vie id.%0A     * %0A
+     * @param id TMDb id.%0A
      * @return B
@@ -1098,32 +1098,32 @@
 ilder instance.%0A
-
      */%0A    publ
@@ -1206,32 +1206,354 @@
 is, id);%0A    %7D%0A%0A
+    /**%0A     * Get the basic movie information for a specific movie id.%0A     * %0A     * @param id TMDb id.%0A     * @param langCode ISO 639-1 code.%0A     * @return Builder instance.%0A     */%0A    public SummaryBuilder summary(Integer id, String langCode) %7B%0A        return new SummaryBuilder(this, id).language(langCode);%0A    %7D%0A%0A
     /**%0A     * G
@@ -1593,32 +1593,58 @@
 vie id.%0A     * %0A
+     * @param id TMDb id.%0A
      * @return B
@@ -1959,24 +1959,24 @@
 popular() %7B%0A
-
         retu
@@ -2003,32 +2003,347 @@
 r(this);%0A    %7D%0A%0A
+    /**%0A     * Get the list of popular movies on The Movie Database. This list refreshes%0A     * every day.%0A     * %0A     * @param langCode ISO 639-1 code.%0A     * @return Builder instance.%0A     */%0A    public PopularBuilder popular(String langCode) %7B%0A        return new PopularBuilder(this).language(langCode);%0A    %7D%0A%0A
     public stati

Add methods to MovieService which use language codes.