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

"""
    easybimehlanding

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

from easybimehlanding.api_helper import APIHelper
from easybimehlanding.configuration import Configuration
from easybimehlanding.controllers.base_controller import BaseController
from easybimehlanding.models.base_model_traking_code import BaseModelTrakingCode
from easybimehlanding.models.tracking_damage import TrackingDamage
from easybimehlanding.models.base_model_status_status_collections import BaseModelStatusStatusCollections
from easybimehlanding.models.base_model_status import BaseModelStatus
from easybimehlanding.exceptions.status_400_exception import Status400Exception

class TrackingDamageController(BaseController):

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


    def get_tracking_code(self,
                          tracking_code,
                          x_api_key):
        """Does a GET request to /TrackingDamage/TrackingCode/.

        استعلام وضعیت خسارت

        Args:
            tracking_code (string): کد پیگیری خسارت
            x_api_key (string): کلید اختصاصی ارتباط با سرور

        Returns:
            BaseModelTrakingCode: 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 = '/TrackingDamage/TrackingCode/'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            '/{TrackingCode}': tracking_code
        }
        _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',
            'x-api-key': x_api_key
        }

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

        # Endpoint and global error handling using HTTP status codes.
        if _context.response.status_code == 400:
            raise Status400Exception('Bad Request', _context)
        self.validate_response(_context)

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

    def create_tracking_damage(self,
                               body,
                               x_api_key,
                               content_type):
        """Does a POST request to /TrackingDamage.

        ثبت خسارت بیمه

        Args:
            body (TrackingDamageRequest): اطلاعات خسارت
            x_api_key (string): کلید اختصاصی ارتباط با سرور
            content_type (string): TODO: type description here. Example: 

        Returns:
            TrackingDamage: 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 = '/TrackingDamage'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_url = APIHelper.clean_url(_query_builder)

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

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

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

    def get_status_status_collections(self,
                                      status_type,
                                      x_api_key):
        """Does a GET request to /Status/StatusCollections.

        دریافت لیست وضعیت های خسارت

        Args:
            status_type (int): نوع وضعیت ها ی خسارت => 0
            x_api_key (string): کلید اختصاصی ارتباط با سرور

        Returns:
            BaseModelStatusStatusCollections: 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 = '/Status/StatusCollections'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'statusType': status_type
        }
        _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',
            'x-api-key': x_api_key
        }

        # 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, BaseModelStatusStatusCollections.from_dictionary)

    def get_status(self,
                   entity_id,
                   x_api_key):
        """Does a GET request to /Status.

        دریافت اطلاعات وضعیت

        Args:
            entity_id (int): شناسه ی وضعیت
            x_api_key (string): کلید اختصاصی ارتباط با سرور

        Returns:
            BaseModelStatus: 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 = '/Status'
        _query_builder = Configuration.get_base_uri()
        _query_builder += _url_path
        _query_parameters = {
            'entityId': entity_id
        }
        _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',
            'x-api-key': x_api_key
        }

        # 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, BaseModelStatus.from_dictionary)
