# coding: utf-8

"""


    Generated by: https://openapi-generator.tech
"""

from dataclasses import dataclass
import typing_extensions
import urllib3
from urllib3._collections import HTTPHeaderDict

from banyanclient import api_client, exceptions
from datetime import date, datetime  # noqa: F401
import decimal  # noqa: F401
import functools  # noqa: F401
import io  # noqa: F401
import re  # noqa: F401
import typing  # noqa: F401
import typing_extensions  # noqa: F401
import uuid  # noqa: F401

import frozendict  # noqa: F401

from banyanclient import schemas  # noqa: F401

from . import path

# query params
BeforeSchema = schemas.IntSchema
AfterSchema = schemas.IntSchema
TypeSchema = schemas.StrSchema
SubTypeSchema = schemas.StrSchema
UserEmailSchema = schemas.StrSchema
DeviceIdSchema = schemas.StrSchema
SerialnumberSchema = schemas.StrSchema
WorkloadContainerIdSchema = schemas.StrSchema
ServiceNameSchema = schemas.StrSchema
ActionSchema = schemas.StrSchema
IdSchema = schemas.StrSchema
ExternalIdSchema = schemas.StrSchema
SeveritySchema = schemas.StrSchema
ServiceAccountNameSchema = schemas.StrSchema
StartTimeSchema = schemas.IntSchema
EndTimeSchema = schemas.IntSchema
RequestRequiredQueryParams = typing_extensions.TypedDict(
    'RequestRequiredQueryParams',
    {
    }
)
RequestOptionalQueryParams = typing_extensions.TypedDict(
    'RequestOptionalQueryParams',
    {
        'before': typing.Union[BeforeSchema, decimal.Decimal, int, ],
        'after': typing.Union[AfterSchema, decimal.Decimal, int, ],
        'type': typing.Union[TypeSchema, str, ],
        'sub_type': typing.Union[SubTypeSchema, str, ],
        'user_email': typing.Union[UserEmailSchema, str, ],
        'device_id': typing.Union[DeviceIdSchema, str, ],
        'serialnumber': typing.Union[SerialnumberSchema, str, ],
        'workload_container_id': typing.Union[WorkloadContainerIdSchema, str, ],
        'service_name': typing.Union[ServiceNameSchema, str, ],
        'action': typing.Union[ActionSchema, str, ],
        'id': typing.Union[IdSchema, str, ],
        'external_id': typing.Union[ExternalIdSchema, str, ],
        'severity': typing.Union[SeveritySchema, str, ],
        'service_account_name': typing.Union[ServiceAccountNameSchema, str, ],
        'start_time': typing.Union[StartTimeSchema, decimal.Decimal, int, ],
        'end_time': typing.Union[EndTimeSchema, decimal.Decimal, int, ],
    },
    total=False
)


class RequestQueryParams(RequestRequiredQueryParams, RequestOptionalQueryParams):
    pass


request_query_before = api_client.QueryParameter(
    name="before",
    style=api_client.ParameterStyle.FORM,
    schema=BeforeSchema,
    explode=True,
)
request_query_after = api_client.QueryParameter(
    name="after",
    style=api_client.ParameterStyle.FORM,
    schema=AfterSchema,
    explode=True,
)
request_query_type = api_client.QueryParameter(
    name="type",
    style=api_client.ParameterStyle.FORM,
    schema=TypeSchema,
    explode=True,
)
request_query_sub_type = api_client.QueryParameter(
    name="sub_type",
    style=api_client.ParameterStyle.FORM,
    schema=SubTypeSchema,
    explode=True,
)
request_query_user_email = api_client.QueryParameter(
    name="user_email",
    style=api_client.ParameterStyle.FORM,
    schema=UserEmailSchema,
    explode=True,
)
request_query_device_id = api_client.QueryParameter(
    name="device_id",
    style=api_client.ParameterStyle.FORM,
    schema=DeviceIdSchema,
    explode=True,
)
request_query_serialnumber = api_client.QueryParameter(
    name="serialnumber",
    style=api_client.ParameterStyle.FORM,
    schema=SerialnumberSchema,
    explode=True,
)
request_query_workload_container_id = api_client.QueryParameter(
    name="workload_container_id",
    style=api_client.ParameterStyle.FORM,
    schema=WorkloadContainerIdSchema,
    explode=True,
)
request_query_service_name = api_client.QueryParameter(
    name="service_name",
    style=api_client.ParameterStyle.FORM,
    schema=ServiceNameSchema,
    explode=True,
)
request_query_action = api_client.QueryParameter(
    name="action",
    style=api_client.ParameterStyle.FORM,
    schema=ActionSchema,
    explode=True,
)
request_query_id = api_client.QueryParameter(
    name="id",
    style=api_client.ParameterStyle.FORM,
    schema=IdSchema,
    explode=True,
)
request_query_external_id = api_client.QueryParameter(
    name="external_id",
    style=api_client.ParameterStyle.FORM,
    schema=ExternalIdSchema,
    explode=True,
)
request_query_severity = api_client.QueryParameter(
    name="severity",
    style=api_client.ParameterStyle.FORM,
    schema=SeveritySchema,
    explode=True,
)
request_query_service_account_name = api_client.QueryParameter(
    name="service_account_name",
    style=api_client.ParameterStyle.FORM,
    schema=ServiceAccountNameSchema,
    explode=True,
)
request_query_start_time = api_client.QueryParameter(
    name="start_time",
    style=api_client.ParameterStyle.FORM,
    schema=StartTimeSchema,
    explode=True,
)
request_query_end_time = api_client.QueryParameter(
    name="end_time",
    style=api_client.ParameterStyle.FORM,
    schema=EndTimeSchema,
    explode=True,
)
_auth = [
    'bearerAuthToken',
]


class SchemaFor200ResponseBodyApplicationJson(
    schemas.DictSchema
):


    class MetaOapg:
        
        class properties:
            data = schemas.IntSchema
            __annotations__ = {
                "data": data,
            }
    
    @typing.overload
    def __getitem__(self, name: typing_extensions.Literal["data"]) -> MetaOapg.properties.data: ...
    
    @typing.overload
    def __getitem__(self, name: str) -> schemas.UnsetAnyTypeSchema: ...
    
    def __getitem__(self, name: typing.Union[typing_extensions.Literal["data", ], str]):
        # dict_instance[name] accessor
        return super().__getitem__(name)
    
    
    @typing.overload
    def get_item_oapg(self, name: typing_extensions.Literal["data"]) -> typing.Union[MetaOapg.properties.data, schemas.Unset]: ...
    
    @typing.overload
    def get_item_oapg(self, name: str) -> typing.Union[schemas.UnsetAnyTypeSchema, schemas.Unset]: ...
    
    def get_item_oapg(self, name: typing.Union[typing_extensions.Literal["data", ], str]):
        return super().get_item_oapg(name)
    

    def __new__(
        cls,
        *args: typing.Union[dict, frozendict.frozendict, ],
        data: typing.Union[MetaOapg.properties.data, decimal.Decimal, int, schemas.Unset] = schemas.unset,
        _configuration: typing.Optional[schemas.Configuration] = None,
        **kwargs: typing.Union[schemas.AnyTypeSchema, dict, frozendict.frozendict, str, date, datetime, uuid.UUID, int, float, decimal.Decimal, None, list, tuple, bytes],
    ) -> 'SchemaFor200ResponseBodyApplicationJson':
        return super().__new__(
            cls,
            *args,
            data=data,
            _configuration=_configuration,
            **kwargs,
        )


@dataclass
class ApiResponseFor200(api_client.ApiResponse):
    response: urllib3.HTTPResponse
    body: typing.Union[
        SchemaFor200ResponseBodyApplicationJson,
    ]
    headers: schemas.Unset = schemas.unset


_response_for_200 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor200,
    content={
        'application/json': api_client.MediaType(
            schema=SchemaFor200ResponseBodyApplicationJson),
    },
)


@dataclass
class ApiResponseFor401(api_client.ApiResponse):
    response: urllib3.HTTPResponse
    body: schemas.Unset = schemas.unset
    headers: schemas.Unset = schemas.unset


_response_for_401 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor401,
)


@dataclass
class ApiResponseFor403(api_client.ApiResponse):
    response: urllib3.HTTPResponse
    body: schemas.Unset = schemas.unset
    headers: schemas.Unset = schemas.unset


_response_for_403 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor403,
)


@dataclass
class ApiResponseFor500(api_client.ApiResponse):
    response: urllib3.HTTPResponse
    body: schemas.Unset = schemas.unset
    headers: schemas.Unset = schemas.unset


_response_for_500 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor500,
)
_status_code_to_response = {
    '200': _response_for_200,
    '401': _response_for_401,
    '403': _response_for_403,
    '500': _response_for_500,
}
_all_accept_content_types = (
    'application/json',
)


class BaseApi(api_client.Api):

    def _v1_events_count_get_oapg(
        self: api_client.Api,
        query_params: RequestQueryParams = frozendict.frozendict(),
        accept_content_types: typing.Tuple[str] = _all_accept_content_types,
        stream: bool = False,
        timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
        skip_deserialization: bool = False,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization
    ]:
        """
         Get Events Count
        :param skip_deserialization: If true then api_response.response will be set but
            api_response.body and api_response.headers will not be deserialized into schema
            class instances
        """
        self._verify_typed_dict_inputs_oapg(RequestQueryParams, query_params)
        used_path = path.value

        prefix_separator_iterator = None
        for parameter in (
            request_query_before,
            request_query_after,
            request_query_type,
            request_query_sub_type,
            request_query_user_email,
            request_query_device_id,
            request_query_serialnumber,
            request_query_workload_container_id,
            request_query_service_name,
            request_query_action,
            request_query_id,
            request_query_external_id,
            request_query_severity,
            request_query_service_account_name,
            request_query_start_time,
            request_query_end_time,
        ):
            parameter_data = query_params.get(parameter.name, schemas.unset)
            if parameter_data is schemas.unset:
                continue
            if prefix_separator_iterator is None:
                prefix_separator_iterator = parameter.get_prefix_separator_iterator()
            serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
            for serialized_value in serialized_data.values():
                used_path += serialized_value

        _headers = HTTPHeaderDict()
        # TODO add cookie handling
        if accept_content_types:
            for accept_content_type in accept_content_types:
                _headers.add('Accept', accept_content_type)

        response = self.api_client.call_api(
            resource_path=used_path,
            method='get'.upper(),
            headers=_headers,
            auth_settings=_auth,
            stream=stream,
            timeout=timeout,
        )

        if skip_deserialization:
            api_response = api_client.ApiResponseWithoutDeserialization(response=response)
        else:
            response_for_status = _status_code_to_response.get(str(response.status))
            if response_for_status:
                api_response = response_for_status.deserialize(response, self.api_client.configuration)
            else:
                api_response = api_client.ApiResponseWithoutDeserialization(response=response)

        if not 200 <= response.status <= 299:
            raise exceptions.ApiException(api_response=api_response)

        return api_response


class V1EventsCountGet(BaseApi):
    # this class is used by api classes that refer to endpoints with operationId fn names

    def v1_events_count_get(
        self: BaseApi,
        query_params: RequestQueryParams = frozendict.frozendict(),
        accept_content_types: typing.Tuple[str] = _all_accept_content_types,
        stream: bool = False,
        timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
        skip_deserialization: bool = False,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization
    ]:
        return self._v1_events_count_get_oapg(
            query_params=query_params,
            accept_content_types=accept_content_types,
            stream=stream,
            timeout=timeout,
            skip_deserialization=skip_deserialization
        )


class ApiForget(BaseApi):
    # this class is used by api classes that refer to endpoints by path and http method names

    def get(
        self: BaseApi,
        query_params: RequestQueryParams = frozendict.frozendict(),
        accept_content_types: typing.Tuple[str] = _all_accept_content_types,
        stream: bool = False,
        timeout: typing.Optional[typing.Union[int, typing.Tuple]] = None,
        skip_deserialization: bool = False,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization
    ]:
        return self._v1_events_count_get_oapg(
            query_params=query_params,
            accept_content_types=accept_content_types,
            stream=stream,
            timeout=timeout,
            skip_deserialization=skip_deserialization
        )


