# -*- 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.models.authorization import Authorization

class AuthorizationController(BaseController):

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


    def get_login(self,
                  username,
                  password):
        """Does a GET request to /authc/login.

        In order to begin utilizing the platform APIs, your application must
        be authenticated and authorized to access domain resources. Follow the
        URL with your credentials and obtain an authorization token which is
        used in every request.
        You will have 2 types of tokens. One is on the PMS level, and this one
        should be used when you send requests related to PMS/PM data. For
        managing properties, you will need a token on PM level, with PM
        credentials. For every API call it will be noted which API credentials
        you should use.

        Args:
            username (string): Your account email address (for PMS or PM)
            password (string): Your password

        Returns:
            Authorization: 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 = '/authc/login'
        _query_builder = Configuration.base_uri
        _query_builder += _url_path
        _query_parameters = {
            'username': username,
            'password': password
        }
        _query_builder = APIHelper.append_url_with_query_parameters(_query_builder,
            _query_parameters, Configuration.array_serialization)
        _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)
        _context = self.execute_request(_request)
        self.validate_response(_context)

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