# coding: utf-8

"""
    Allegro REST API

    https://developer.allegro.pl/about  # noqa: E501

    OpenAPI spec version: latest
    Generated by: https://openapi-generator.tech
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from allegro_api.api_client import ApiClient


class PublicOfferInformationApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def get_listing(self, **kwargs):  # noqa: E501
        """Search offers  # noqa: E501

        Use this resource to get a list of offers according to provided parameters. At least one of: phrase, seller.id or category.id is required. Additional available parameters vary depending on category.id. The parameters are defined in the filters entity. More information about this resource you can find <a href=\"../../news/2018-07-03-listing_ofert/\" target=\"_blank\">here</a>.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_listing(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str category_id: The category identifier to search.
        :param str phrase: Search phrase.
        :param str seller_id: Identifier of the seller. May be provided more than once. Only items of provided sellers are returned.
        :param str search_mode: Search mode. Allowed values: *REGULAR* - searching for a phrase in the title of offers; *DESCRIPTIONS* - searching for a phrase in titles and offers descriptions; *CLOSED* -  searching for a phrase in titles of closed offers. Default *REGULAR*.
        :param int offset: Index of first returned offer from all search results.
        :param int limit: Maximum number of offers in response (acceptable values: from 0 to 100, default is 60).
        :param str sort: Search results sorting order. Allowed values (+ or no prefix means ascending order, - prefix means descending order): relevance, +price, -price, +withDeliveryPrice, -withDeliveryPrice, -popularity, +endTime, -startTime. The default sorting order is relevancy.
        :param str include: Specify parts that should be included in the output. Allowed values are names of top level entities and *all* as an alias to all entities. By default, all top level entities are included. Use \"-\" prefix to exclude entity. Example: *include=-all&include=filters&include=sort* - returns only filters and sort entities.
        :param bool fallback: Defines behaviour of searching when no results with exact phrase match are found: *true* - related (not exact) results are returned; *false* - empty results are returned. The default is true.
        :return: ListingResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('async_req'):
            return self.get_listing_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_listing_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_listing_with_http_info(self, **kwargs):  # noqa: E501
        """Search offers  # noqa: E501

        Use this resource to get a list of offers according to provided parameters. At least one of: phrase, seller.id or category.id is required. Additional available parameters vary depending on category.id. The parameters are defined in the filters entity. More information about this resource you can find <a href=\"../../news/2018-07-03-listing_ofert/\" target=\"_blank\">here</a>.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True
        >>> thread = api.get_listing_with_http_info(async_req=True)
        >>> result = thread.get()

        :param async_req bool
        :param str category_id: The category identifier to search.
        :param str phrase: Search phrase.
        :param str seller_id: Identifier of the seller. May be provided more than once. Only items of provided sellers are returned.
        :param str search_mode: Search mode. Allowed values: *REGULAR* - searching for a phrase in the title of offers; *DESCRIPTIONS* - searching for a phrase in titles and offers descriptions; *CLOSED* -  searching for a phrase in titles of closed offers. Default *REGULAR*.
        :param int offset: Index of first returned offer from all search results.
        :param int limit: Maximum number of offers in response (acceptable values: from 0 to 100, default is 60).
        :param str sort: Search results sorting order. Allowed values (+ or no prefix means ascending order, - prefix means descending order): relevance, +price, -price, +withDeliveryPrice, -withDeliveryPrice, -popularity, +endTime, -startTime. The default sorting order is relevancy.
        :param str include: Specify parts that should be included in the output. Allowed values are names of top level entities and *all* as an alias to all entities. By default, all top level entities are included. Use \"-\" prefix to exclude entity. Example: *include=-all&include=filters&include=sort* - returns only filters and sort entities.
        :param bool fallback: Defines behaviour of searching when no results with exact phrase match are found: *true* - related (not exact) results are returned; *false* - empty results are returned. The default is true.
        :return: ListingResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        local_var_params = locals()

        all_params = ['category_id', 'phrase', 'seller_id', 'search_mode', 'offset', 'limit', 'sort', 'include', 'fallback']  # noqa: E501
        all_params.append('async_req')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        for key, val in six.iteritems(local_var_params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_listing" % key
                )
            local_var_params[key] = val
        del local_var_params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []
        if 'category_id' in local_var_params:
            query_params.append(('category.id', local_var_params['category_id']))  # noqa: E501
        if 'phrase' in local_var_params:
            query_params.append(('phrase', local_var_params['phrase']))  # noqa: E501
        if 'seller_id' in local_var_params:
            query_params.append(('seller.id', local_var_params['seller_id']))  # noqa: E501
        if 'search_mode' in local_var_params:
            query_params.append(('searchMode', local_var_params['search_mode']))  # noqa: E501
        if 'offset' in local_var_params:
            query_params.append(('offset', local_var_params['offset']))  # noqa: E501
        if 'limit' in local_var_params:
            query_params.append(('limit', local_var_params['limit']))  # noqa: E501
        if 'sort' in local_var_params:
            query_params.append(('sort', local_var_params['sort']))  # noqa: E501
        if 'include' in local_var_params:
            query_params.append(('include', local_var_params['include']))  # noqa: E501
        if 'fallback' in local_var_params:
            query_params.append(('fallback', local_var_params['fallback']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/vnd.allegro.public.v1+json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['bearer-token-for-application', 'bearer-token-for-user']  # noqa: E501

        return self.api_client.call_api(
            '/offers/listing', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ListingResponse',  # noqa: E501
            auth_settings=auth_settings,
            async_req=local_var_params.get('async_req'),
            _return_http_data_only=local_var_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=local_var_params.get('_preload_content', True),
            _request_timeout=local_var_params.get('_request_timeout'),
            collection_formats=collection_formats)
