# -*- 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.users_info_response import UsersInfoResponse
from instagramapi.models.users_paging_response import UsersPagingResponse
from instagramapi.models.relationship_response import RelationshipResponse
from instagramapi.models.relationship_post_response import RelationshipPostResponse


class RelationshipsController(BaseController):

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

    def list_the_users_who_have_requested_this_user_s_permission_to_follow(self):
        """Does a GET request to /users/self/requested-by.

        List the users who have requested this user's permission to follow.

        Returns:
            UsersInfoResponse: Response from the API. List of users who have
                requested this user's permission to follow.

        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/requested-by')
            .http_method(HttpMethodEnum.GET)
            .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()

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

        Get the list of users this user is followed by. To get users followed
        by the owner of the access token, you
        can use **self** instead of the `user-id`.

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

        Returns:
            UsersPagingResponse: Response from the API. List of users this
                user is followed by.

        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}/followed-by')
            .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(UsersPagingResponse.from_dictionary)
        ).execute()

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

        Get the list of users this user follows. To get follows of the owner
        of the access token, you can use **self**
        instead of the `user-id`.

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

        Returns:
            UsersPagingResponse: Response from the API. List of users this
                user follows.

        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}/follows')
            .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(UsersPagingResponse.from_dictionary)
        ).execute()

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

        Get information about a relationship to another user.

        Args:
            user_id (str): The ID of a user to get information about.

        Returns:
            RelationshipResponse: Response from the API. Relationship
                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}/relationship')
            .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(RelationshipResponse.from_dictionary)
        ).execute()

    def modify_the_relationship_between_the_current_user_and_the_target_user(self,
                                                                             user_id,
                                                                             action):
        """Does a POST request to /users/{user-id}/relationship.

        Modify the relationship between the current user and the target user.

        Args:
            user_id (str): The ID of the target user.
            action (ActionEnum): Type of action to apply for relationship with
                the user.

        Returns:
            RelationshipPostResponse: Response from the API. Relationship
                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}/relationship')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('user-id')
                            .value(user_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('action')
                         .value(action))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(RelationshipPostResponse.from_dictionary)
        ).execute()
