# coding: utf-8

"""
    Ringer Business API - Call Records

    This API provides an endpoint for retrieving Call Detail Records (CDRs). Call records offer detailed information about calls made or received through the Ringer Business system, including source, destination, duration, cost, and timestamps.  Access to call records can be filtered by time range, paginated, sorted, and filtered by various call attributes. Permissions might vary; administrators may see all records for an organization, while individual users might only see their own. 

    The version of the OpenAPI document: 1.0.0
    Contact: support@ringer.tel
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501

import warnings
from pydantic import validate_call, Field, StrictFloat, StrictStr, StrictInt
from typing import Any, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated

from datetime import datetime
from pydantic import Field, StrictStr, field_validator
from typing import Optional
from typing_extensions import Annotated
from ringer_business.models.call_record_list_response import CallRecordListResponse

from ringer_business.api_client import ApiClient, RequestSerialized
from ringer_business.api_response import ApiResponse
from ringer_business.rest import RESTResponseType


class CallRecordsApi:
    """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) -> None:
        if api_client is None:
            api_client = ApiClient.get_default()
        self.api_client = api_client


    @validate_call
    def list_call_records(
        self,
        start_time: Annotated[datetime, Field(description="Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days. ")],
        page_number: Annotated[int, Field(strict=True, ge=1, description="Page number for pagination.")],
        page_size: Annotated[int, Field(le=100, strict=True, ge=1, description="Number of records per page.")],
        end_time: Annotated[Optional[datetime], Field(description="End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.")] = None,
        sort_column: Annotated[Optional[StrictStr], Field(description="Column to sort by.")] = None,
        sort_type: Annotated[Optional[StrictStr], Field(description="Sort direction.")] = None,
        filter_column: Annotated[Optional[StrictStr], Field(description="Column to filter on.")] = None,
        filter_type: Annotated[Optional[StrictStr], Field(description="Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. ")] = None,
        filter_value: Annotated[Optional[StrictStr], Field(description="Value to filter by.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> CallRecordListResponse:
        """List Call Records

        Retrieves a list of Call Detail Records (CDRs) based on specified criteria. Allows for time-based querying, pagination, sorting, and filtering by call attributes like DNI, ANI, duration, etc. The scope of returned records may depend on the authenticated user's role (e.g., account admin vs. individual user). A maximum of 30 days worth of data can be queried at a time. 

        :param start_time: Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days.  (required)
        :type start_time: datetime
        :param page_number: Page number for pagination. (required)
        :type page_number: int
        :param page_size: Number of records per page. (required)
        :type page_size: int
        :param end_time: End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.
        :type end_time: datetime
        :param sort_column: Column to sort by.
        :type sort_column: str
        :param sort_type: Sort direction.
        :type sort_type: str
        :param filter_column: Column to filter on.
        :type filter_column: str
        :param filter_type: Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. 
        :type filter_type: str
        :param filter_value: Value to filter by.
        :type filter_value: str
        :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.
        :type _request_timeout: int, tuple(int, int), optional
        :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
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """ # noqa: E501

        _param = self._list_call_records_serialize(
            start_time=start_time,
            page_number=page_number,
            page_size=page_size,
            end_time=end_time,
            sort_column=sort_column,
            sort_type=sort_type,
            filter_column=filter_column,
            filter_type=filter_type,
            filter_value=filter_value,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "CallRecordListResponse",
            '400': "CallRecordError",
            '401': "Error",
            '403': "Error",
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        ).data


    @validate_call
    def list_call_records_with_http_info(
        self,
        start_time: Annotated[datetime, Field(description="Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days. ")],
        page_number: Annotated[int, Field(strict=True, ge=1, description="Page number for pagination.")],
        page_size: Annotated[int, Field(le=100, strict=True, ge=1, description="Number of records per page.")],
        end_time: Annotated[Optional[datetime], Field(description="End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.")] = None,
        sort_column: Annotated[Optional[StrictStr], Field(description="Column to sort by.")] = None,
        sort_type: Annotated[Optional[StrictStr], Field(description="Sort direction.")] = None,
        filter_column: Annotated[Optional[StrictStr], Field(description="Column to filter on.")] = None,
        filter_type: Annotated[Optional[StrictStr], Field(description="Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. ")] = None,
        filter_value: Annotated[Optional[StrictStr], Field(description="Value to filter by.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> ApiResponse[CallRecordListResponse]:
        """List Call Records

        Retrieves a list of Call Detail Records (CDRs) based on specified criteria. Allows for time-based querying, pagination, sorting, and filtering by call attributes like DNI, ANI, duration, etc. The scope of returned records may depend on the authenticated user's role (e.g., account admin vs. individual user). A maximum of 30 days worth of data can be queried at a time. 

        :param start_time: Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days.  (required)
        :type start_time: datetime
        :param page_number: Page number for pagination. (required)
        :type page_number: int
        :param page_size: Number of records per page. (required)
        :type page_size: int
        :param end_time: End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.
        :type end_time: datetime
        :param sort_column: Column to sort by.
        :type sort_column: str
        :param sort_type: Sort direction.
        :type sort_type: str
        :param filter_column: Column to filter on.
        :type filter_column: str
        :param filter_type: Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. 
        :type filter_type: str
        :param filter_value: Value to filter by.
        :type filter_value: str
        :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.
        :type _request_timeout: int, tuple(int, int), optional
        :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
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """ # noqa: E501

        _param = self._list_call_records_serialize(
            start_time=start_time,
            page_number=page_number,
            page_size=page_size,
            end_time=end_time,
            sort_column=sort_column,
            sort_type=sort_type,
            filter_column=filter_column,
            filter_type=filter_type,
            filter_value=filter_value,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "CallRecordListResponse",
            '400': "CallRecordError",
            '401': "Error",
            '403': "Error",
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        response_data.read()
        return self.api_client.response_deserialize(
            response_data=response_data,
            response_types_map=_response_types_map,
        )


    @validate_call
    def list_call_records_without_preload_content(
        self,
        start_time: Annotated[datetime, Field(description="Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days. ")],
        page_number: Annotated[int, Field(strict=True, ge=1, description="Page number for pagination.")],
        page_size: Annotated[int, Field(le=100, strict=True, ge=1, description="Number of records per page.")],
        end_time: Annotated[Optional[datetime], Field(description="End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.")] = None,
        sort_column: Annotated[Optional[StrictStr], Field(description="Column to sort by.")] = None,
        sort_type: Annotated[Optional[StrictStr], Field(description="Sort direction.")] = None,
        filter_column: Annotated[Optional[StrictStr], Field(description="Column to filter on.")] = None,
        filter_type: Annotated[Optional[StrictStr], Field(description="Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. ")] = None,
        filter_value: Annotated[Optional[StrictStr], Field(description="Value to filter by.")] = None,
        _request_timeout: Union[
            None,
            Annotated[StrictFloat, Field(gt=0)],
            Tuple[
                Annotated[StrictFloat, Field(gt=0)],
                Annotated[StrictFloat, Field(gt=0)]
            ]
        ] = None,
        _request_auth: Optional[Dict[StrictStr, Any]] = None,
        _content_type: Optional[StrictStr] = None,
        _headers: Optional[Dict[StrictStr, Any]] = None,
        _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0,
    ) -> RESTResponseType:
        """List Call Records

        Retrieves a list of Call Detail Records (CDRs) based on specified criteria. Allows for time-based querying, pagination, sorting, and filtering by call attributes like DNI, ANI, duration, etc. The scope of returned records may depend on the authenticated user's role (e.g., account admin vs. individual user). A maximum of 30 days worth of data can be queried at a time. 

        :param start_time: Start timestamp for the query range (ISO 8601 format, e.g., \"2021-06-01T00:00:00Z\"). Maximum query window is 30 days.  (required)
        :type start_time: datetime
        :param page_number: Page number for pagination. (required)
        :type page_number: int
        :param page_size: Number of records per page. (required)
        :type page_size: int
        :param end_time: End timestamp for the query range (ISO 8601 format). Defaults to current time if omitted.
        :type end_time: datetime
        :param sort_column: Column to sort by.
        :type sort_column: str
        :param sort_type: Sort direction.
        :type sort_type: str
        :param filter_column: Column to filter on.
        :type filter_column: str
        :param filter_type: Filter operator. `starts_with`, `ends_with`, `contains` only for `raw_ani` or `dni`. 
        :type filter_type: str
        :param filter_value: Value to filter by.
        :type filter_value: str
        :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.
        :type _request_timeout: int, tuple(int, int), optional
        :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
        :param _content_type: force content-type for the request.
        :type _content_type: str, Optional
        :param _headers: set to override the headers for a single
                         request; this effectively ignores the headers
                         in the spec for a single request.
        :type _headers: dict, optional
        :param _host_index: set to override the host_index for a single
                            request; this effectively ignores the host_index
                            in the spec for a single request.
        :type _host_index: int, optional
        :return: Returns the result object.
        """ # noqa: E501

        _param = self._list_call_records_serialize(
            start_time=start_time,
            page_number=page_number,
            page_size=page_size,
            end_time=end_time,
            sort_column=sort_column,
            sort_type=sort_type,
            filter_column=filter_column,
            filter_type=filter_type,
            filter_value=filter_value,
            _request_auth=_request_auth,
            _content_type=_content_type,
            _headers=_headers,
            _host_index=_host_index
        )

        _response_types_map: Dict[str, Optional[str]] = {
            '200': "CallRecordListResponse",
            '400': "CallRecordError",
            '401': "Error",
            '403': "Error",
        }
        response_data = self.api_client.call_api(
            *_param,
            _request_timeout=_request_timeout
        )
        return response_data.response


    def _list_call_records_serialize(
        self,
        start_time,
        page_number,
        page_size,
        end_time,
        sort_column,
        sort_type,
        filter_column,
        filter_type,
        filter_value,
        _request_auth,
        _content_type,
        _headers,
        _host_index,
    ) -> RequestSerialized:

        _host = None

        _collection_formats: Dict[str, str] = {
        }

        _path_params: Dict[str, str] = {}
        _query_params: List[Tuple[str, str]] = []
        _header_params: Dict[str, Optional[str]] = _headers or {}
        _form_params: List[Tuple[str, str]] = []
        _files: Dict[
            str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]]
        ] = {}
        _body_params: Optional[bytes] = None

        # process the path parameters
        # process the query parameters
        if start_time is not None:
            if isinstance(start_time, datetime):
                _query_params.append(
                    (
                        'start_time',
                        start_time.strftime(
                            self.api_client.configuration.datetime_format
                        )
                    )
                )
            else:
                _query_params.append(('start_time', start_time))
            
        if end_time is not None:
            if isinstance(end_time, datetime):
                _query_params.append(
                    (
                        'end_time',
                        end_time.strftime(
                            self.api_client.configuration.datetime_format
                        )
                    )
                )
            else:
                _query_params.append(('end_time', end_time))
            
        if page_number is not None:
            
            _query_params.append(('page[number]', page_number))
            
        if page_size is not None:
            
            _query_params.append(('page[size]', page_size))
            
        if sort_column is not None:
            
            _query_params.append(('sort[column]', sort_column))
            
        if sort_type is not None:
            
            _query_params.append(('sort[type]', sort_type))
            
        if filter_column is not None:
            
            _query_params.append(('filter[column]', filter_column))
            
        if filter_type is not None:
            
            _query_params.append(('filter[type]', filter_type))
            
        if filter_value is not None:
            
            _query_params.append(('filter[value]', filter_value))
            
        # process the header parameters
        # process the form parameters
        # process the body parameter


        # set the HTTP header `Accept`
        if 'Accept' not in _header_params:
            _header_params['Accept'] = self.api_client.select_header_accept(
                [
                    'application/json'
                ]
            )


        # authentication setting
        _auth_settings: List[str] = [
            'oAuth2'
        ]

        return self.api_client.param_serialize(
            method='GET',
            resource_path='/call-records',
            path_params=_path_params,
            query_params=_query_params,
            header_params=_header_params,
            body=_body_params,
            post_params=_form_params,
            files=_files,
            auth_settings=_auth_settings,
            collection_formats=_collection_formats,
            _host=_host,
            _request_auth=_request_auth
        )


