<commit_before>﻿namespace TraktApiSharp.Modules
{
    using Enums;
    using Extensions;
    using Objects.Basic;
    using Requests;
    using Requests.Params;
    using Requests.WithoutOAuth.Search;
    using System;
    using System.Threading.Tasks;

    /// <summary>
    /// Provides access to data retrieving methods specific to search.
    /// <para>
    /// This module contains all methods of the <a href ="http://docs.trakt.apiary.io/#reference/search">"Trakt API Doc - Search"</a> section.
    /// </para>
    /// </summary>
    public class TraktSearchModule : TraktBaseModule
    {
        internal TraktSearchModule(TraktClient client) : base(client) { }

        /// <summary>
        /// Searches for movies, shows, episodes, people and / or lists with the given search query.
        /// <para>OAuth authorization not required.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-text-query-results">"Trakt API Doc - Search: Text Query"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchResultType">
        /// The object type(s), for which will be searched. See also <seealso cref="TraktSearchResultType" />.
        /// Multiple <see cref="TraktSearchResultType" /> values can be combined with a binary operator, like this: TraktSearchResultType.Movie | TraktSearchResultType.Show.
        /// </param>
        /// <param name="searchQuery">The query, for which will be searched.</param>
        /// <param name="filter">Optional filter for genres, year, runtimes, ratings, etc. See also <seealso cref="TraktSearchFilter" />.</param>
        /// <param name="extendedOption">
        /// The extended option, which determines how much data about the movies, shows, episodes, people and / or lists should be queried.
        /// See also <seealso cref="TraktExtendedOption" />.
        /// </param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given searchQuery is null, empty or contains spaces.
        /// Thrown, if the given searchResultType is unspecified.
        /// </exception>
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetTextQueryResultsAsync(TraktSearchResultType searchResultType, string searchQuery,
                                                                                                 TraktSearchFilter filter = null,
                                                                                                 TraktExtendedOption extendedOption = null,
                                                                                                 int? page = null, int? limitPerPage = null)
        {
            Validate(searchResultType);
            Validate(searchQuery);

            return await QueryAsync(new TraktSearchTextQueryRequest(Client)
            {
                ResultType = searchResultType,
                Query = searchQuery,
                Filter = filter,
                ExtendedOption = extendedOption,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Looks up items by their Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id.
        /// <para>OAuth authorization not required.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-id-lookup-results">"Trakt API Doc - Search: Id Lookup"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchIdType">The id type, which should be looked up. See also <seealso cref="TraktSearchIdType" />.</param>
        /// <param name="lookupId">The Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id, which will be looked up.</param>
        /// <param name="searchResultType">The object type(s), which will be looked up. See also <seealso cref="TraktSearchResultType" />.</param>
        /// <param name="extendedOption">
        /// The extended option, which determines how much data about the lookup object(s) should be queried.
        /// See also <seealso cref="TraktExtendedOption" />.
        /// </param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given lookupId is null, empty or contains spaces.
        /// Thrown, if the given searchIdType is unspecified.
        /// </exception>
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetIdLookupResultsAsync(TraktSearchIdType searchIdType, string lookupId,
                                                                                                TraktSearchResultType? searchResultType = null,
                                                                                                TraktExtendedOption extendedOption = null,
                                                                                                int? page = null, int? limitPerPage = null)
        {
            Validate(searchIdType, lookupId);

            return await QueryAsync(new TraktSearchIdLookupRequest(Client)
            {
                IdType = searchIdType,
                LookupId = lookupId,
                ResultType = searchResultType,
                ExtendedOption = extendedOption,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Searches for movies, shows, episodes, people and / or lists with the given search query.
        /// <para>OAuth authorization not required.</para>
        /// <para>This method is DEPRECATED. Please use <see cref="GetTextQueryResultsAsync(TraktSearchResultType, string, TraktSearchFilter, TraktExtendedOption, int?, int?)" />.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-text-query-results">"Trakt API Doc - Search: Text Query"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchQuery">The query, for which will be searched.</param>
        /// <param name="searchResultType">The object type, for which will be searched. See also <seealso cref="TraktSearchResultType" />.</param>
        /// <param name="year">The year, for which will be searched.</param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given searchQuery is null, empty or contains spaces.
        /// Thrown, if the given searchResultType has an unspecified value.
        /// </exception>
        [Obsolete("This search method still works, but might be removed in a future release.")]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetTextQueryResultsAsync(string searchQuery, TraktSearchResultType? searchResultType = null,
                                                                                                 int? year = null, int? page = null, int? limitPerPage = null)
        {
            Validate(searchQuery);

            return await QueryAsync(new TraktSearchOldTextQueryRequest(Client)
            {
                Query = searchQuery,
                Type = searchResultType,
                Year = year,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Looks up items by their Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id.
        /// <para>OAuth authorization not required.</para>
        /// <para>This method is DEPRECATED. Please use <see cref="GetIdLookupResultsAsync(TraktSearchIdType, string, TraktSearchResultType?, TraktExtendedOption, int?, int?)" />.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-id-lookup-results">"Trakt API Doc - Search: Id Lookup"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchIdLookupType">The id type, which should be looked up. See also <seealso cref="TraktSearchIdLookupType" />.</param>
        /// <param name="lookupId">The Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id, which will be looked up.</param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given lookupId is null, empty or contains spaces.
        /// Thrown, if the given searchIdLookupType is unspecified.
        /// </exception>
        [Obsolete("This search method still works, but might be removed in a future release.")]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetIdLookupResultsAsync(TraktSearchIdLookupType searchIdLookupType, string lookupId,
                                                                                                int? page = null, int? limitPerPage = null)
        {
            Validate(searchIdLookupType, lookupId);

            return await QueryAsync(new TraktSearchOldIdLookupRequest(Client)
            {
                Type = searchIdLookupType,
                LookupId = lookupId,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        private void Validate(string searchQuery)<commit_msg>Annotate search methods with oauth attribute.<commit_after>﻿namespace TraktApiSharp.Modules
{
    using Attributes;
    using Enums;
    using Extensions;
    using Objects.Basic;
    using Requests;
    using Requests.Params;
    using Requests.WithoutOAuth.Search;
    using System;
    using System.Threading.Tasks;

    /// <summary>
    /// Provides access to data retrieving methods specific to search.
    /// <para>
    /// This module contains all methods of the <a href ="http://docs.trakt.apiary.io/#reference/search">"Trakt API Doc - Search"</a> section.
    /// </para>
    /// </summary>
    public class TraktSearchModule : TraktBaseModule
    {
        internal TraktSearchModule(TraktClient client) : base(client) { }

        /// <summary>
        /// Searches for movies, shows, episodes, people and / or lists with the given search query.
        /// <para>OAuth authorization not required.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-text-query-results">"Trakt API Doc - Search: Text Query"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchResultType">
        /// The object type(s), for which will be searched. See also <seealso cref="TraktSearchResultType" />.
        /// Multiple <see cref="TraktSearchResultType" /> values can be combined with a binary operator, like this: TraktSearchResultType.Movie | TraktSearchResultType.Show.
        /// </param>
        /// <param name="searchQuery">The query, for which will be searched.</param>
        /// <param name="filter">Optional filter for genres, year, runtimes, ratings, etc. See also <seealso cref="TraktSearchFilter" />.</param>
        /// <param name="extendedOption">
        /// The extended option, which determines how much data about the movies, shows, episodes, people and / or lists should be queried.
        /// See also <seealso cref="TraktExtendedOption" />.
        /// </param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given searchQuery is null, empty or contains spaces.
        /// Thrown, if the given searchResultType is unspecified.
        /// </exception>
        [OAuthAuthorizationRequired(false)]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetTextQueryResultsAsync(TraktSearchResultType searchResultType, string searchQuery,
                                                                                                 TraktSearchFilter filter = null,
                                                                                                 TraktExtendedOption extendedOption = null,
                                                                                                 int? page = null, int? limitPerPage = null)
        {
            Validate(searchResultType);
            Validate(searchQuery);

            return await QueryAsync(new TraktSearchTextQueryRequest(Client)
            {
                ResultType = searchResultType,
                Query = searchQuery,
                Filter = filter,
                ExtendedOption = extendedOption,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Looks up items by their Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id.
        /// <para>OAuth authorization not required.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-id-lookup-results">"Trakt API Doc - Search: Id Lookup"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchIdType">The id type, which should be looked up. See also <seealso cref="TraktSearchIdType" />.</param>
        /// <param name="lookupId">The Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id, which will be looked up.</param>
        /// <param name="searchResultType">The object type(s), which will be looked up. See also <seealso cref="TraktSearchResultType" />.</param>
        /// <param name="extendedOption">
        /// The extended option, which determines how much data about the lookup object(s) should be queried.
        /// See also <seealso cref="TraktExtendedOption" />.
        /// </param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given lookupId is null, empty or contains spaces.
        /// Thrown, if the given searchIdType is unspecified.
        /// </exception>
        [OAuthAuthorizationRequired(false)]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetIdLookupResultsAsync(TraktSearchIdType searchIdType, string lookupId,
                                                                                                TraktSearchResultType? searchResultType = null,
                                                                                                TraktExtendedOption extendedOption = null,
                                                                                                int? page = null, int? limitPerPage = null)
        {
            Validate(searchIdType, lookupId);

            return await QueryAsync(new TraktSearchIdLookupRequest(Client)
            {
                IdType = searchIdType,
                LookupId = lookupId,
                ResultType = searchResultType,
                ExtendedOption = extendedOption,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Searches for movies, shows, episodes, people and / or lists with the given search query.
        /// <para>OAuth authorization not required.</para>
        /// <para>This method is DEPRECATED. Please use <see cref="GetTextQueryResultsAsync(TraktSearchResultType, string, TraktSearchFilter, TraktExtendedOption, int?, int?)" />.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-text-query-results">"Trakt API Doc - Search: Text Query"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchQuery">The query, for which will be searched.</param>
        /// <param name="searchResultType">The object type, for which will be searched. See also <seealso cref="TraktSearchResultType" />.</param>
        /// <param name="year">The year, for which will be searched.</param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given searchQuery is null, empty or contains spaces.
        /// Thrown, if the given searchResultType has an unspecified value.
        /// </exception>
        [Obsolete("This search method still works, but might be removed in a future release.")]
        [OAuthAuthorizationRequired(false)]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetTextQueryResultsAsync(string searchQuery, TraktSearchResultType? searchResultType = null,
                                                                                                 int? year = null, int? page = null, int? limitPerPage = null)
        {
            Validate(searchQuery);

            return await QueryAsync(new TraktSearchOldTextQueryRequest(Client)
            {
                Query = searchQuery,
                Type = searchResultType,
                Year = year,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        /// <summary>
        /// Looks up items by their Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id.
        /// <para>OAuth authorization not required.</para>
        /// <para>This method is DEPRECATED. Please use <see cref="GetIdLookupResultsAsync(TraktSearchIdType, string, TraktSearchResultType?, TraktExtendedOption, int?, int?)" />.</para>
        /// <para>
        /// See <a href="http://docs.trakt.apiary.io/#reference/search/text-query/get-id-lookup-results">"Trakt API Doc - Search: Id Lookup"</a> for more information.
        /// </para>
        /// </summary>
        /// <param name="searchIdLookupType">The id type, which should be looked up. See also <seealso cref="TraktSearchIdLookupType" />.</param>
        /// <param name="lookupId">The Trakt-, IMDB-, TMDB-, TVDB- or TVRage-Id, which will be looked up.</param>
        /// <param name="page">The page of the search results list, that should be queried. Defaults to the first page.</param>
        /// <param name="limitPerPage">The maximum count of results for each page, that should be queried.</param>
        /// <returns>
        /// An <see cref="TraktPaginationListResult{TraktSearchResult}"/> instance containing the found movies, shows, episodes, people and / or lists and which also
        /// contains the queried page number, the page's item count, maximum page count and maximum item count.
        /// <para>
        /// See also <seealso cref="TraktPaginationListResult{ListItem}" /> and <seealso cref="TraktSearchResult" />.
        /// </para>
        /// </returns>
        /// <exception cref="Exceptions.TraktException">Thrown, if the request fails.</exception>
        /// <exception cref="ArgumentException">
        /// Thrown, if the given lookupId is null, empty or contains spaces.
        /// Thrown, if the given searchIdLookupType is unspecified.
        /// </exception>
        [Obsolete("This search method still works, but might be removed in a future release.")]
        [OAuthAuthorizationRequired(false)]
        public async Task<TraktPaginationListResult<TraktSearchResult>> GetIdLookupResultsAsync(TraktSearchIdLookupType searchIdLookupType, string lookupId,
                                                                                                int? page = null, int? limitPerPage = null)
        {
            Validate(searchIdLookupType, lookupId);

            return await QueryAsync(new TraktSearchOldIdLookupRequest(Client)
            {
                Type = searchIdLookupType,
                LookupId = lookupId,
                PaginationOptions = new TraktPaginationOptions(page, limitPerPage)
            });
        }

        private void Validate(string searchQuery)
{'fraction_non_alphanumeric': 0.11233182071491123, 'fraction_numerical': 0.0, 'mean_word_length': 2.059676044330776, 'pattern_counts': {'":': 0, '<': 297, '<?xml version=': 0, '>': 297, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 64, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1558353', 'n_tokens_mistral': 6185, 'n_tokens_neox': 6089, 'n_words': 1960}