# coding: utf-8

"""
    Billing API

    Billing API allows users to retrieve billing reports and service package details.

    OpenAPI spec version: 1.4.7
    
    Generated by: https://github.com/swagger-api/swagger-codegen.git
"""


from __future__ import absolute_import

import re  # noqa: F401

# python 2 and python 3 compatibility library
import six

from ..api_client import ApiClient


class DefaultApi(object):
    """NOTE: This class is auto generated by the swagger code generator program.

    Do not edit the class manually.
    Ref: https://github.com/swagger-api/swagger-codegen
    """

    def __init__(self, api_client=None):
        if api_client is None:
            api_client = ApiClient()
        self.api_client = api_client

    def get_billing_report(self, month, **kwargs):  # noqa: E501
        """Get billing report.  # noqa: E501

        Fetch the billing report generated for the currently authenticated commercial non-subtenant account. Billing reports for subtenant accounts are included in their aggregator's billing report response.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: ReportResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_billing_report_with_http_info(month, **kwargs)  # noqa: E501
        else:
            (data) = self.get_billing_report_with_http_info(month, **kwargs)  # noqa: E501
            return data

    def get_billing_report_with_http_info(self, month, **kwargs):  # noqa: E501
        """Get billing report.  # noqa: E501

        Fetch the billing report generated for the currently authenticated commercial non-subtenant account. Billing reports for subtenant accounts are included in their aggregator's billing report response.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report_with_http_info(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: ReportResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['month']  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_billing_report" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'month' is set
        if ('month' not in params or
                params['month'] is None):
            raise ValueError("Missing the required parameter `month` when calling `get_billing_report`")  # noqa: E501

        if 'month' in params and not re.search('^\\d{4}-\\d{2}$', params['month']):  # noqa: E501
            raise ValueError("Invalid value for parameter `month` when calling `get_billing_report`, must conform to the pattern `/^\\d{4}-\\d{2}$/`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'month' in params:
            query_params.append(('month', params['month']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/billing-report', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ReportResponse',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_billing_report_active_devices(self, month, **kwargs):  # noqa: E501
        """Get raw billing data of the active devices for the month.  # noqa: E501

        Fetch the raw billing data of the active devices for the currently authenticated commercial non-subtenant account. This is supplementary data for the billing report. The raw billing data of the active devices for subtenant accounts are included in their aggregator's raw billing data of the active devices. The endpoint returns the URL to download the gzipped CSV file. The first line is the header providing information on the active devices. For example, the ID of an active device.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report-active-devices?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report_active_devices(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: BillingReportRawDataResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_billing_report_active_devices_with_http_info(month, **kwargs)  # noqa: E501
        else:
            (data) = self.get_billing_report_active_devices_with_http_info(month, **kwargs)  # noqa: E501
            return data

    def get_billing_report_active_devices_with_http_info(self, month, **kwargs):  # noqa: E501
        """Get raw billing data of the active devices for the month.  # noqa: E501

        Fetch the raw billing data of the active devices for the currently authenticated commercial non-subtenant account. This is supplementary data for the billing report. The raw billing data of the active devices for subtenant accounts are included in their aggregator's raw billing data of the active devices. The endpoint returns the URL to download the gzipped CSV file. The first line is the header providing information on the active devices. For example, the ID of an active device.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report-active-devices?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report_active_devices_with_http_info(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: BillingReportRawDataResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['month']  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_billing_report_active_devices" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'month' is set
        if ('month' not in params or
                params['month'] is None):
            raise ValueError("Missing the required parameter `month` when calling `get_billing_report_active_devices`")  # noqa: E501

        if 'month' in params and not re.search('^\\d{4}-\\d{2}$', params['month']):  # noqa: E501
            raise ValueError("Invalid value for parameter `month` when calling `get_billing_report_active_devices`, must conform to the pattern `/^\\d{4}-\\d{2}$/`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'month' in params:
            query_params.append(('month', params['month']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/billing-report-active-devices', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='BillingReportRawDataResponse',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_billing_report_firmware_updates(self, month, **kwargs):  # noqa: E501
        """Get raw billing data of the firmware updates for the month.  # noqa: E501

        Fetch raw billing data of the firmware updates for the currently authenticated commercial non-subtenant account. This is supplementary data for the billing report. The raw billing data of the firmware updates for subtenant accounts are included in their aggregator's raw billing data of the firmware updates. The endpoint returns the URL to download the gzipped CSV file. The first line is the header providing information on the firmware updates. For example, the ID of an firmware update.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report-firmware-updates?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report_firmware_updates(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: BillingReportRawDataResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_billing_report_firmware_updates_with_http_info(month, **kwargs)  # noqa: E501
        else:
            (data) = self.get_billing_report_firmware_updates_with_http_info(month, **kwargs)  # noqa: E501
            return data

    def get_billing_report_firmware_updates_with_http_info(self, month, **kwargs):  # noqa: E501
        """Get raw billing data of the firmware updates for the month.  # noqa: E501

        Fetch raw billing data of the firmware updates for the currently authenticated commercial non-subtenant account. This is supplementary data for the billing report. The raw billing data of the firmware updates for subtenant accounts are included in their aggregator's raw billing data of the firmware updates. The endpoint returns the URL to download the gzipped CSV file. The first line is the header providing information on the firmware updates. For example, the ID of an firmware update.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/billing-report-firmware-updates?month=2018-07 -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_billing_report_firmware_updates_with_http_info(month, asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param str month: Queried year and month of billing report. (required)
        :return: BillingReportRawDataResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['month']  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_billing_report_firmware_updates" % key
                )
            params[key] = val
        del params['kwargs']
        # verify the required parameter 'month' is set
        if ('month' not in params or
                params['month'] is None):
            raise ValueError("Missing the required parameter `month` when calling `get_billing_report_firmware_updates`")  # noqa: E501

        if 'month' in params and not re.search('^\\d{4}-\\d{2}$', params['month']):  # noqa: E501
            raise ValueError("Invalid value for parameter `month` when calling `get_billing_report_firmware_updates`, must conform to the pattern `/^\\d{4}-\\d{2}$/`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'month' in params:
            query_params.append(('month', params['month']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/billing-report-firmware-updates', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='BillingReportRawDataResponse',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_service_package_quota(self, **kwargs):  # noqa: E501
        """Service package quota.  # noqa: E501

        Get the available firmware update quota for the currently authenticated commercial account.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages-quota -H 'authorization: Bearer {api-key}'   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_package_quota(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :return: ServicePackageQuota
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_service_package_quota_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_service_package_quota_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_service_package_quota_with_http_info(self, **kwargs):  # noqa: E501
        """Service package quota.  # noqa: E501

        Get the available firmware update quota for the currently authenticated commercial account.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages-quota -H 'authorization: Bearer {api-key}'   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_package_quota_with_http_info(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :return: ServicePackageQuota
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_service_package_quota" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/service-packages-quota', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ServicePackageQuota',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_service_package_quota_history(self, **kwargs):  # noqa: E501
        """Service package quota history.  # noqa: E501

        Get your quota usage history. This API is available for commercial accounts. Aggregator accounts can see own and subtenant quota usage data. History data is ordered in ascending order based on the added timestamp.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages-quota-history -H 'authorization: Bearer {api-key}'   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_package_quota_history(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param int limit: Maximum amount of quota history entries contained in one paged response.
        :param str after: To fetch after which quota history ID. The results will contain entries after specified entry.
        :return: ServicePackageQuotaHistoryResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_service_package_quota_history_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_service_package_quota_history_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_service_package_quota_history_with_http_info(self, **kwargs):  # noqa: E501
        """Service package quota history.  # noqa: E501

        Get your quota usage history. This API is available for commercial accounts. Aggregator accounts can see own and subtenant quota usage data. History data is ordered in ascending order based on the added timestamp.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages-quota-history -H 'authorization: Bearer {api-key}'   # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_package_quota_history_with_http_info(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :param int limit: Maximum amount of quota history entries contained in one paged response.
        :param str after: To fetch after which quota history ID. The results will contain entries after specified entry.
        :return: ServicePackageQuotaHistoryResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = ['limit', 'after']  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_service_package_quota_history" % key
                )
            params[key] = val
        del params['kwargs']

        if 'limit' in params and params['limit'] > 1000:  # noqa: E501
            raise ValueError("Invalid value for parameter `limit` when calling `get_service_package_quota_history`, must be a value less than or equal to `1000`")  # noqa: E501
        if 'limit' in params and params['limit'] < 2:  # noqa: E501
            raise ValueError("Invalid value for parameter `limit` when calling `get_service_package_quota_history`, must be a value greater than or equal to `2`")  # noqa: E501
        if ('after' in params and
                len(params['after']) > 32):
            raise ValueError("Invalid value for parameter `after` when calling `get_service_package_quota_history`, length must be less than or equal to `32`")  # noqa: E501
        if ('after' in params and
                len(params['after']) < 32):
            raise ValueError("Invalid value for parameter `after` when calling `get_service_package_quota_history`, length must be greater than or equal to `32`")  # noqa: E501
        collection_formats = {}

        path_params = {}

        query_params = []
        if 'limit' in params:
            query_params.append(('limit', params['limit']))  # noqa: E501
        if 'after' in params:
            query_params.append(('after', params['after']))  # noqa: E501

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/service-packages-quota-history', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ServicePackageQuotaHistoryResponse',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)

    def get_service_packages(self, **kwargs):  # noqa: E501
        """Get all service packages.  # noqa: E501

        Get information of all service packages for the currently authenticated commercial account. The response is returned in descending order by service package created timestamp, listing first the pending service package, then the active service package and finally the previous service packages.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_packages(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :return: ServicePackagesResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """
        kwargs['_return_http_data_only'] = True
        if kwargs.get('asynchronous'):
            return self.get_service_packages_with_http_info(**kwargs)  # noqa: E501
        else:
            (data) = self.get_service_packages_with_http_info(**kwargs)  # noqa: E501
            return data

    def get_service_packages_with_http_info(self, **kwargs):  # noqa: E501
        """Get all service packages.  # noqa: E501

        Get information of all service packages for the currently authenticated commercial account. The response is returned in descending order by service package created timestamp, listing first the pending service package, then the active service package and finally the previous service packages.  **Example usage:**      curl -X GET https://api.us-east-1.mbedcloud.com/v3/service-packages -H 'authorization: Bearer {api-key}'  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass asynchronous=True
        >>> thread = api.get_service_packages_with_http_info(asynchronous=True)
        >>> result = thread.get()

        :param asynchronous bool
        :return: ServicePackagesResponse
                 If the method is called asynchronously,
                 returns the request thread.
        """

        all_params = []  # noqa: E501
        all_params.append('asynchronous')
        all_params.append('_return_http_data_only')
        all_params.append('_preload_content')
        all_params.append('_request_timeout')

        params = locals()
        for key, val in six.iteritems(params['kwargs']):
            if key not in all_params:
                raise TypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method get_service_packages" % key
                )
            params[key] = val
        del params['kwargs']

        collection_formats = {}

        path_params = {}

        query_params = []

        header_params = {}

        form_params = []
        local_var_files = {}

        body_params = None
        # HTTP header `Accept`
        header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # Authentication setting
        auth_settings = ['Bearer']  # noqa: E501

        return self.api_client.call_api(
            '/v3/service-packages', 'GET',
            path_params,
            query_params,
            header_params,
            body=body_params,
            post_params=form_params,
            files=local_var_files,
            response_type='ServicePackagesResponse',  # noqa: E501
            auth_settings=auth_settings,
            asynchronous=params.get('asynchronous'),
            _return_http_data_only=params.get('_return_http_data_only'),
            _preload_content=params.get('_preload_content', True),
            _request_timeout=params.get('_request_timeout'),
            collection_formats=collection_formats)
