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

"""
instagramapi

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

from deprecation import deprecated
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.users_info_response import UsersInfoResponse
from instagramapi.models.media_list_response import MediaListResponse
from instagramapi.models.user_response import UserResponse
from instagramapi.exceptions.api_exception import APIException


class UsersController(BaseController):

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

    def search_for_a_user_by_name(self,
                                  q,
                                  count=None):
        """Does a GET request to /users/search.

        Search for a user by name.

        Args:
            q (str): A query string.
            count (int, optional): Number of users to return.

        Returns:
            UsersInfoResponse: Response from the API. List of found users.

        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('/users/search')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('q')
                         .value(q))
            .query_param(Parameter()
                         .key('count')
                         .value(count))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(UsersInfoResponse.from_dictionary)
        ).execute()

    @deprecated()
    def see_the_authenticated_user_s_feed(self,
                                          count=None,
                                          min_id=None,
                                          max_id=None):
        """Does a GET request to /users/self/feed.

        See the authenticated user's feed.
        **Warning:** [Deprecated](http://instagram.com/developer/changelog/)
        for Apps created **on or after** Nov 17, 2015

        Args:
            count (int, optional): Count of media to return.
            min_id (str, optional): Return media later than this `min_id`.
            max_id (str, optional): Return media earlier than this `max_id`.

        Returns:
            MediaListResponse: Response from the API. Users feed entries.

        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('/users/self/feed')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('count')
                         .value(count))
            .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()

    def see_the_list_of_media_liked_by_the_authenticated_user(self,
                                                              count=None,
                                                              max_like_id=None):
        """Does a GET request to /users/self/media/liked.

        See the list of media liked by the authenticated user. Private media
        is returned as long as the authenticated
        user has permission to view that media. Liked media lists are only
        available for the currently authenticated
        user.

        Args:
            count (int, optional): Count of media to return.
            max_like_id (str, optional): Return media liked before this id.

        Returns:
            MediaListResponse: Response from the API. Users media entries.

        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('/users/self/media/liked')
            .http_method(HttpMethodEnum.GET)
            .query_param(Parameter()
                         .key('count')
                         .value(count))
            .query_param(Parameter()
                         .key('max_like_id')
                         .value(max_like_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()

    def get_basic_information_about_a_user(self,
                                           user_id):
        """Does a GET request to /users/{user-id}.

        Get basic information about a user. To get information about the owner
        of the access token, you can use
        **self** instead of the `user-id`.
        Security scope `public_content` is required to read information about
        other users.

        Args:
            user_id (str): The ID of a user to get information about, or
                **self** to retrieve information about authenticated user.

        Returns:
            UserResponse: Response from the API. User basic information.

        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('/users/{user-id}')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('user-id')
                            .value(user_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(UserResponse.from_dictionary)
            .local_error('404', 'Not Found, user with such ID does not exist.', APIException)
        ).execute()

    def get_the_most_recent_media_published_by_a_user(self,
                                                      user_id,
                                                      count=None,
                                                      max_timestamp=None,
                                                      min_timestamp=None,
                                                      min_id=None,
                                                      max_id=None):
        """Does a GET request to /users/{user-id}/media/recent.

        Get the most recent media published by a user. To get the most recent
        media published by the owner of the
        access token, you can use **self** instead of the `user-id`.
        Security scope `public_content` is required to read information about
        other users.

        Args:
            user_id (str): The ID of a user to get recent media of, or
                **self** to retrieve media of authenticated user.
            count (int, optional): Count of media to return.
            max_timestamp (int, optional): Return media before this UNIX
                timestamp.
            min_timestamp (int, optional): Return media after this UNIX
                timestamp.
            min_id (str, optional): Return media later than this `min_id`.
            max_id (str, optional): Return media earlier than this `max_id`.

        Returns:
            MediaListResponse: Response from the API. Users media entries.

        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('/users/{user-id}/media/recent')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('user-id')
                            .value(user_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('count')
                         .value(count))
            .query_param(Parameter()
                         .key('max_timestamp')
                         .value(max_timestamp))
            .query_param(Parameter()
                         .key('min_timestamp')
                         .value(min_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()
