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


class LikesController(BaseController):

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

    def remove_a_like_on_this_media_by_the_current_user(self,
                                                        media_id):
        """Does a DELETE request to /media/{media-id}/likes.

        Remove a like on this media by the currently authenticated user.

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

        Returns:
            StatusResponse: Response from the API. Result of removing a like.

        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}/likes')
            .http_method(HttpMethodEnum.DELETE)
            .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(StatusResponse.from_dictionary)
        ).execute()

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

        Get a list of users who have liked this media.

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

        Returns:
            UsersInfoResponse: Response from the API. List of users who liked
                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}/likes')
            .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(UsersInfoResponse.from_dictionary)
        ).execute()

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

        Set a like on this media by the currently authenticated user.

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

        Returns:
            StatusResponse: Response from the API. Result of setting a like.

        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}/likes')
            .http_method(HttpMethodEnum.POST)
            .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(StatusResponse.from_dictionary)
        ).execute()
