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

"""
    apimaticcalculatorlatest

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

from apimaticcalculatorlatest.api_helper import APIHelper
from apimaticcalculatorlatest.configuration import Configuration
from apimaticcalculatorlatest.controllers.base_controller import BaseController
from apimaticcalculatorlatest.http.auth.custom_query_auth import CustomQueryAuth
from apimaticcalculatorlatest.models.yieldresponse import Yieldresponse

class YieldsController(BaseController):

    """A Controller to access Endpoints in the apimaticcalculatorlatest API."""


    def get_ym_rlistbyproduct_id(self,
                                 product_id):
        """Does a GET request to /yield/{productId}.

        This function allows the logged in user to get yield management rules
        list of the specific product.

        Args:
            product_id (string): ID of the property

        Returns:
            Yieldresponse: Response from the API. 

        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.

        """

        # Prepare query URL
        _url_path = '/yield/{productId}'
        _url_path = APIHelper.append_url_with_template_parameters(_url_path, { 
            'productId': product_id
        })
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json'
        }

        # Prepare and execute request
        _request = self.http_client.get(_query_url, headers=_headers)
        CustomQueryAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, Yieldresponse.from_dictionary)

    def create_ymr(self,
                   content_type,
                   body):
        """Does a POST request to /yield.

        This function allows the logged-in user to add yield management rules
        for the specific product. Yield management rules can affect the final
        price of the property depending on some special conditions (like the
        length of stay, early booking, etc.). These rules automate price
        manipulations, on an inquiry by inquiry basis. When set criteria are
        met, they help maximize revenue and occupancy.
        How is the price calculated?
        The price for a night is calculated based on the basic price and the
        yield management rules.
        - If no YMR:
        {basic price per night} = price per night
        - If YMR is set it can Increase/decrease percent or increase/decrease
        amount:
        	{basic price per night} + {yield amount} = {price per night}
        	or
        	{basic price per night} - {yield amount} = {price per night}
        The below examples will use the scenario to walk you step by step and
        explain how the price is calculated based on different YMRs. 
        Let’s say that the basic price per night for 2016 is 100 USD.
        This function is used also for updating yield. So if you already
        create a specific yield for some date - and you send a new one - we
        will update the yield for this date.
        If you need to delete a specific yield type - you can send an empty
        list for that type.
        Important: The maximum allowed end date is 3 years in the future.

        Args:
            content_type (string): TODO: type description here. Example: 
            body (CreateYieldRequest): TODO: type description here. Example: 

        Returns:
            Yieldresponse: Response from the API. 

        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.

        """

        # Prepare query URL
        _url_path = '/yield'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

        # Prepare headers
        _headers = {
            'accept': 'application/json',
            'Content-Type': content_type
        }

        # Prepare and execute request
        _request = self.http_client.post(_query_url, headers=_headers, parameters=APIHelper.json_serialize(body))
        CustomQueryAuth.apply(_request)
        _context = self.execute_request(_request)
        self.validate_response(_context)

        # Return appropriate type
        return APIHelper.json_deserialize(_context.response.raw_body, Yieldresponse.from_dictionary)
