# -*- 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.comments_response import CommentsResponse
from instagramapi.models.status_response import StatusResponse


class CommentsController(BaseController):

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

    def get_a_list_of_recent_comments_on_a_media_object(self,
                                                        media_id):
        """Does a GET request to /media/{media-id}/comments.

        Get a list of recent comments on a media object.

        Args:
            media_id (str): The ID of the media resource.

        Returns:
            CommentsResponse: Response from the API. List of comments of the
                media resource.

        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('/media/{media-id}/comments')
            .http_method(HttpMethodEnum.GET)
            .template_param(Parameter()
                            .key('media-id')
                            .value(media_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(CommentsResponse.from_dictionary)
        ).execute()

    def create_a_comment_on_a_media_object(self,
                                           media_id,
                                           text):
        """Does a POST request to /media/{media-id}/comments.

        Create a comment on a media object with the following rules:
          * The total length of the comment cannot exceed 300 characters.
          * The comment cannot contain more than 4 hashtags.
          * The comment cannot contain more than 1 URL.
          * The comment cannot consist of all capital letters.

        Args:
            media_id (str): The ID of the media resource.
            text (str): Text to post as a comment on the media object as
                specified in `media-id`.

        Returns:
            StatusResponse: Response from the API. Result of posting a comment.

        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('/media/{media-id}/comments')
            .http_method(HttpMethodEnum.POST)
            .template_param(Parameter()
                            .key('media-id')
                            .value(media_id)
                            .should_encode(True))
            .query_param(Parameter()
                         .key('text')
                         .value(text))
            .header_param(Parameter()
                          .key('accept')
                          .value('application/json'))
            .auth(Or(Single('api_key'), Single('instagram_auth')))
        ).response(
            ResponseHandler()
            .deserializer(APIHelper.json_deserialize)
            .deserialize_into(StatusResponse.from_dictionary)
        ).execute()

    def remove_a_comment(self,
                         media_id,
                         comment_id):
        """Does a DELETE request to /media/{media-id}/comments/{comment-id}.

        Remove a comment either on the authenticated user's media object or
        authored by the authenticated user.

        Args:
            media_id (str): The ID of the media resource.
            comment_id (str): The ID of the comment entry.

        Returns:
            StatusResponse: Response from the API. Result of deleting a
                comment.

        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('/media/{media-id}/comments/{comment-id}')
            .http_method(HttpMethodEnum.DELETE)
            .template_param(Parameter()
                            .key('media-id')
                            .value(media_id)
                            .should_encode(True))
            .template_param(Parameter()
                            .key('comment-id')
                            .value(comment_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(StatusResponse.from_dictionary)
        ).execute()
