# -*- coding: utf-8 -*-

"""
instagramapi

This file was automatically generated by APIMATIC v3.0 (
 https://www.apimatic.io ).
"""

from instagramapi.api_helper import APIHelper
from instagramapi.configuration import Server
from instagramapi.controllers.base_controller import BaseController
from apimatic_core.request_builder import RequestBuilder
from apimatic_core.response_handler import ResponseHandler
from apimatic_core.types.parameter import Parameter
from instagramapi.http.http_method_enum import HttpMethodEnum
from apimatic_core.authentication.multiple.single_auth import Single
from apimatic_core.authentication.multiple.or_auth_group import Or
from instagramapi.models.location_search_response import LocationSearchResponse
from instagramapi.models.location_info_response import LocationInfoResponse
from instagramapi.models.media_list_response import MediaListResponse


class LocationsController(BaseController):

    """A Controller to access Endpoints in the instagramapi API."""
    def __init__(self, config):
        super(LocationsController, self).__init__(config)

    def search_for_a_location_by_geographic_coordinate(self,
                                                       distance=None,
                                                       facebook_places_id=None,
                                                       foursquare_id=None,
                                                       lat=None,
                                                       lng=None,
                                                       foursquare_v_2_id=None):
        """Does a GET request to /locations/search.

        Search for a location by geographic coordinate.

        Args:
            distance (int, optional): Default is 1000m (distance=1000), max
                distance is 5000.
            facebook_places_id (str, optional): Returns a location mapped off
                of a Facebook places id. If used, a Foursquare id and `lat`,
                `lng` are not required.
            foursquare_id (str, optional): Returns a location mapped off of a
                foursquare v1 api location id. If used, you are not required
                to use `lat` and `lng`. Note that this method is deprecated;
                you should use the new foursquare IDs with V2 of their API.
            lat (float, optional): Latitude of the center search coordinate.
                If used, `lng` is required.
            lng (float, optional): Longitude of the center search coordinate.
                If used, `lat` is required.
            foursquare_v_2_id (str, optional): Returns a location mapped off
                of a foursquare v2 api location id. If used, you are not
                required to use `lat` and `lng`.

        Returns:
            LocationSearchResponse: Response from the API. List of found
                locations.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/locations/search')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('distance')
                         .value(distance))
            .query_param(Parameter()
                         .key('facebook_places_id')
                         .value(facebook_places_id))
            .query_param(Parameter()
                         .key('foursquare_id')
                         .value(foursquare_id))
            .query_param(Parameter()
                         .key('lat')
                         .value(lat))
            .query_param(Parameter()
                         .key('lng')
                         .value(lng))
            .query_param(Parameter()
                         .key('foursquare_v2_id')
                         .value(foursquare_v_2_id))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(LocationSearchResponse.from_dictionary)
        ).execute()

    def get_information_about_a_location(self,
                                         location_id):
        """Does a GET request to /locations/{location-id}.

        Get information about a location.

        Args:
            location_id (str): The location ID.

        Returns:
            LocationInfoResponse: Response from the API. Location information
                response.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/locations/{location-id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('location-id')
                            .value(location_id)
                            .should_encode(True))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(LocationInfoResponse.from_dictionary)
        ).execute()

    def get_a_list_of_recent_media_objects_from_a_given_location(self,
                                                                 location_id,
                                                                 min_timestamp=None,
                                                                 max_timestamp=None,
                                                                 min_id=None,
                                                                 max_id=None):
        """Does a GET request to /locations/{location-id}/media/recent.

        Get a list of recent media objects from a given location.

        Args:
            location_id (str): The location ID.
            min_timestamp (int, optional): Return media after this UNIX
                timestamp.
            max_timestamp (int, optional): Return media before this UNIX
                timestamp.
            min_id (str, optional): Return media before this `min_id`.
            max_id (str, optional): Return media after this `max_id`.

        Returns:
            MediaListResponse: Response from the API. List of media entries
                from this location.

        Raises:
            APIException: When an error occurs while fetching the data from
                the remote API. This exception includes the HTTP Response
                code, an error message, and the HTTP body that was received in
                the request.

        """

        return super().new_api_call_builder.request(
            RequestBuilder().server(Server.DEFAULT)
            .path('/locations/{location-id}/media/recent')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('location-id')
                            .value(location_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('min_timestamp')
                         .value(min_timestamp))
            .query_param(Parameter()
                         .key('max_timestamp')
                         .value(max_timestamp))
            .query_param(Parameter()
                         .key('min_id')
                         .value(min_id))
            .query_param(Parameter()
                         .key('max_id')
                         .value(max_id))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(MediaListResponse.from_dictionary)
        ).execute()
