# coding: utf-8

"""
    Gigs Core API

    API to manage voice & data plans for smartphones, wearables and IoT in 200+ countries.  # noqa: E501

    The version of the OpenAPI document: 0.0.1
    Contact: support@gigs.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


import re  # noqa: F401
import io
import warnings

from pydantic import validate_arguments, ValidationError
from typing_extensions import Annotated

from pydantic import Field

from typing import Any, Optional

from gigs_client.models.subscription_usage_list200_response import SubscriptionUsageList200Response

from gigs_client.api_client import ApiClient
from gigs_client.api_response import ApiResponse
from gigs_client.exceptions import (  # noqa: F401
    ApiTypeError,
    ApiValueError
)


class UsageApi(object):
    """NOTE: This class is auto generated by OpenAPI Generator
    Ref: https://openapi-generator.tech

    Do not edit the class manually.
    """

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

    @validate_arguments
    def subscription_usage_list(self, project : Annotated[Any, Field(..., description="The unique identifier for the [project](https://developers.gigs.com/docs/api/b3A6MzMwODcxMzI-retrieve-a-project).")], id : Annotated[Any, Field(..., description="The unique identifier for the subscription.")], period : Annotated[Optional[Any], Field(description="Limits the usage data returned to the subscription period provided. This option is incompatible with the `start` and `end` parameters.")] = None, start : Annotated[Optional[Any], Field(description="Limits the usage data to dates greater than or equal to the provided date. Can only be used in combination with `end`.")] = None, end : Annotated[Optional[Any], Field(description="Limits the usage data to dates up to and including the provided date. Can only be used in combination with `start`.")] = None, aggregation : Annotated[Optional[Any], Field(description="Determines the aggregation method used, defaulting to `daily`. `period` provides a single aggregated value for the time range or period requested.")] = None, **kwargs) -> SubscriptionUsageList200Response:  # noqa: E501
        """List subscription usage records  # noqa: E501

        Lists usage records in ascending order for a subscription, defaulting to `daily` aggregation for the latest subscription period. If none of the `start`, `end`, or `period` parameters is provided, records are returned for the latest subscription period.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.subscription_usage_list(project, id, period, start, end, aggregation, async_req=True)
        >>> result = thread.get()

        :param project: The unique identifier for the [project](https://developers.gigs.com/docs/api/b3A6MzMwODcxMzI-retrieve-a-project). (required)
        :type project: object
        :param id: The unique identifier for the subscription. (required)
        :type id: object
        :param period: Limits the usage data returned to the subscription period provided. This option is incompatible with the `start` and `end` parameters.
        :type period: object
        :param start: Limits the usage data to dates greater than or equal to the provided date. Can only be used in combination with `end`.
        :type start: object
        :param end: Limits the usage data to dates up to and including the provided date. Can only be used in combination with `start`.
        :type end: object
        :param aggregation: Determines the aggregation method used, defaulting to `daily`. `period` provides a single aggregated value for the time range or period requested.
        :type aggregation: object
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: SubscriptionUsageList200Response
        """
        kwargs['_return_http_data_only'] = True
        if '_preload_content' in kwargs:
            raise ValueError("Error! Please call the subscription_usage_list_with_http_info method with `_preload_content` instead and obtain raw data from ApiResponse.raw_data")
        return self.subscription_usage_list_with_http_info(project, id, period, start, end, aggregation, **kwargs)  # noqa: E501

    @validate_arguments
    def subscription_usage_list_with_http_info(self, project : Annotated[Any, Field(..., description="The unique identifier for the [project](https://developers.gigs.com/docs/api/b3A6MzMwODcxMzI-retrieve-a-project).")], id : Annotated[Any, Field(..., description="The unique identifier for the subscription.")], period : Annotated[Optional[Any], Field(description="Limits the usage data returned to the subscription period provided. This option is incompatible with the `start` and `end` parameters.")] = None, start : Annotated[Optional[Any], Field(description="Limits the usage data to dates greater than or equal to the provided date. Can only be used in combination with `end`.")] = None, end : Annotated[Optional[Any], Field(description="Limits the usage data to dates up to and including the provided date. Can only be used in combination with `start`.")] = None, aggregation : Annotated[Optional[Any], Field(description="Determines the aggregation method used, defaulting to `daily`. `period` provides a single aggregated value for the time range or period requested.")] = None, **kwargs) -> ApiResponse:  # noqa: E501
        """List subscription usage records  # noqa: E501

        Lists usage records in ascending order for a subscription, defaulting to `daily` aggregation for the latest subscription period. If none of the `start`, `end`, or `period` parameters is provided, records are returned for the latest subscription period.  # noqa: E501
        This method makes a synchronous HTTP request by default. To make an
        asynchronous HTTP request, please pass async_req=True

        >>> thread = api.subscription_usage_list_with_http_info(project, id, period, start, end, aggregation, async_req=True)
        >>> result = thread.get()

        :param project: The unique identifier for the [project](https://developers.gigs.com/docs/api/b3A6MzMwODcxMzI-retrieve-a-project). (required)
        :type project: object
        :param id: The unique identifier for the subscription. (required)
        :type id: object
        :param period: Limits the usage data returned to the subscription period provided. This option is incompatible with the `start` and `end` parameters.
        :type period: object
        :param start: Limits the usage data to dates greater than or equal to the provided date. Can only be used in combination with `end`.
        :type start: object
        :param end: Limits the usage data to dates up to and including the provided date. Can only be used in combination with `start`.
        :type end: object
        :param aggregation: Determines the aggregation method used, defaulting to `daily`. `period` provides a single aggregated value for the time range or period requested.
        :type aggregation: object
        :param async_req: Whether to execute the request asynchronously.
        :type async_req: bool, optional
        :param _preload_content: if False, the ApiResponse.data will
                                 be set to none and raw_data will store the 
                                 HTTP response body without reading/decoding.
                                 Default is True.
        :type _preload_content: bool, optional
        :param _return_http_data_only: response data instead of ApiResponse
                                       object with status code, headers, etc
        :type _return_http_data_only: bool, optional
        :param _request_timeout: timeout setting for this request. If one
                                 number provided, it will be total request
                                 timeout. It can also be a pair (tuple) of
                                 (connection, read) timeouts.
        :param _request_auth: set to override the auth_settings for an a single
                              request; this effectively ignores the authentication
                              in the spec for a single request.
        :type _request_auth: dict, optional
        :type _content_type: string, optional: force content-type for the request
        :return: Returns the result object.
                 If the method is called asynchronously,
                 returns the request thread.
        :rtype: tuple(SubscriptionUsageList200Response, status_code(int), headers(HTTPHeaderDict))
        """

        _params = locals()

        _all_params = [
            'project',
            'id',
            'period',
            'start',
            'end',
            'aggregation'
        ]
        _all_params.extend(
            [
                'async_req',
                '_return_http_data_only',
                '_preload_content',
                '_request_timeout',
                '_request_auth',
                '_content_type',
                '_headers'
            ]
        )

        # validate the arguments
        for _key, _val in _params['kwargs'].items():
            if _key not in _all_params:
                raise ApiTypeError(
                    "Got an unexpected keyword argument '%s'"
                    " to method subscription_usage_list" % _key
                )
            _params[_key] = _val
        del _params['kwargs']

        _collection_formats = {}

        # process the path parameters
        _path_params = {}
        if _params['project']:
            _path_params['project'] = _params['project']

        if _params['id']:
            _path_params['id'] = _params['id']


        # process the query parameters
        _query_params = []
        if _params.get('period') is not None:  # noqa: E501
            _query_params.append(('period', _params['period']))

        if _params.get('start') is not None:  # noqa: E501
            _query_params.append(('start', _params['start']))

        if _params.get('end') is not None:  # noqa: E501
            _query_params.append(('end', _params['end']))

        if _params.get('aggregation') is not None:  # noqa: E501
            _query_params.append(('aggregation', _params['aggregation'].value))

        # process the header parameters
        _header_params = dict(_params.get('_headers', {}))
        # process the form parameters
        _form_params = []
        _files = {}
        # process the body parameter
        _body_params = None
        # set the HTTP header `Accept`
        _header_params['Accept'] = self.api_client.select_header_accept(
            ['application/json'])  # noqa: E501

        # authentication setting
        _auth_settings = ['bearerAuth']  # noqa: E501

        _response_types_map = {
            '200': "SubscriptionUsageList200Response",
            '404': None,
            '422': None,
        }

        return self.api_client.call_api(
            '/projects/{project}/subscriptions/{id}/usage', 'GET',
            _path_params,
            _query_params,
            _header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            response_types_map=_response_types_map,
            auth_settings=_auth_settings,
            async_req=_params.get('async_req'),
            _return_http_data_only=_params.get('_return_http_data_only'),  # noqa: E501
            _preload_content=_params.get('_preload_content', True),
            _request_timeout=_params.get('_request_timeout'),
            collection_formats=_collection_formats,
            _request_auth=_params.get('_request_auth'))
