# coding: utf-8

"""


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

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

from onelogin 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 onelogin import schemas  # noqa: F401

from onelogin.model.error import Error
from onelogin.model.user import User

from . import path

# Query params
LimitSchema = schemas.Int32Schema
PageSchema = schemas.IntSchema
CursorSchema = schemas.StrSchema
CreatedSinceSchema = schemas.StrSchema
CreatedUntilSchema = schemas.StrSchema
UpdatedSinceSchema = schemas.StrSchema
UpdatedUntilSchema = schemas.StrSchema
LastLoginSinceSchema = schemas.StrSchema
LastLoginUntilSchema = schemas.StrSchema
FirstnameSchema = schemas.StrSchema
LastnameSchema = schemas.StrSchema
EmailSchema = schemas.StrSchema
UsernameSchema = schemas.StrSchema
SamaccountnameSchema = schemas.StrSchema
DirectoryIdSchema = schemas.IntSchema
ExternalIdSchema = schemas.StrSchema
UserIdsSchema = schemas.StrSchema
CustomAttributesAttributeNameSchema = schemas.StrSchema


class FieldsSchema(
    schemas.EnumBase,
    schemas.StrSchema
):


    class MetaOapg:
        enum_value_to_name = {
            "apps": "APPS",
            "users": "USERS",
            "admins": "ADMINS",
        }
    
    @schemas.classproperty
    def APPS(cls):
        return cls("apps")
    
    @schemas.classproperty
    def USERS(cls):
        return cls("users")
    
    @schemas.classproperty
    def ADMINS(cls):
        return cls("admins")
AppIdSchema = schemas.IntSchema
RequestRequiredQueryParams = typing_extensions.TypedDict(
    'RequestRequiredQueryParams',
    {
    }
)
RequestOptionalQueryParams = typing_extensions.TypedDict(
    'RequestOptionalQueryParams',
    {
        'limit': typing.Union[LimitSchema, decimal.Decimal, int, ],
        'page': typing.Union[PageSchema, decimal.Decimal, int, ],
        'cursor': typing.Union[CursorSchema, str, ],
        'created_since': typing.Union[CreatedSinceSchema, str, ],
        'created_until': typing.Union[CreatedUntilSchema, str, ],
        'updated_since': typing.Union[UpdatedSinceSchema, str, ],
        'updated_until': typing.Union[UpdatedUntilSchema, str, ],
        'last_login_since': typing.Union[LastLoginSinceSchema, str, ],
        'last_login_until': typing.Union[LastLoginUntilSchema, str, ],
        'firstname': typing.Union[FirstnameSchema, str, ],
        'lastname': typing.Union[LastnameSchema, str, ],
        'email': typing.Union[EmailSchema, str, ],
        'username': typing.Union[UsernameSchema, str, ],
        'samaccountname': typing.Union[SamaccountnameSchema, str, ],
        'directory_id': typing.Union[DirectoryIdSchema, decimal.Decimal, int, ],
        'external_id': typing.Union[ExternalIdSchema, str, ],
        'user_ids': typing.Union[UserIdsSchema, str, ],
        'custom_attributes.{attribute_name}': typing.Union[CustomAttributesAttributeNameSchema, str, ],
        'fields': typing.Union[FieldsSchema, str, ],
        'app_id': typing.Union[AppIdSchema, decimal.Decimal, int, ],
    },
    total=False
)


class RequestQueryParams(RequestRequiredQueryParams, RequestOptionalQueryParams):
    pass


request_query_limit = api_client.QueryParameter(
    name="limit",
    style=api_client.ParameterStyle.FORM,
    schema=LimitSchema,
    explode=True,
)
request_query_page = api_client.QueryParameter(
    name="page",
    style=api_client.ParameterStyle.FORM,
    schema=PageSchema,
    explode=True,
)
request_query_cursor = api_client.QueryParameter(
    name="cursor",
    style=api_client.ParameterStyle.FORM,
    schema=CursorSchema,
    explode=True,
)
request_query_created_since = api_client.QueryParameter(
    name="created_since",
    style=api_client.ParameterStyle.FORM,
    schema=CreatedSinceSchema,
    explode=True,
)
request_query_created_until = api_client.QueryParameter(
    name="created_until",
    style=api_client.ParameterStyle.FORM,
    schema=CreatedUntilSchema,
    explode=True,
)
request_query_updated_since = api_client.QueryParameter(
    name="updated_since",
    style=api_client.ParameterStyle.FORM,
    schema=UpdatedSinceSchema,
    explode=True,
)
request_query_updated_until = api_client.QueryParameter(
    name="updated_until",
    style=api_client.ParameterStyle.FORM,
    schema=UpdatedUntilSchema,
    explode=True,
)
request_query_last_login_since = api_client.QueryParameter(
    name="last_login_since",
    style=api_client.ParameterStyle.FORM,
    schema=LastLoginSinceSchema,
    explode=True,
)
request_query_last_login_until = api_client.QueryParameter(
    name="last_login_until",
    style=api_client.ParameterStyle.FORM,
    schema=LastLoginUntilSchema,
    explode=True,
)
request_query_firstname = api_client.QueryParameter(
    name="firstname",
    style=api_client.ParameterStyle.FORM,
    schema=FirstnameSchema,
    explode=True,
)
request_query_lastname = api_client.QueryParameter(
    name="lastname",
    style=api_client.ParameterStyle.FORM,
    schema=LastnameSchema,
    explode=True,
)
request_query_email = api_client.QueryParameter(
    name="email",
    style=api_client.ParameterStyle.FORM,
    schema=EmailSchema,
    explode=True,
)
request_query_username = api_client.QueryParameter(
    name="username",
    style=api_client.ParameterStyle.FORM,
    schema=UsernameSchema,
    explode=True,
)
request_query_samaccountname = api_client.QueryParameter(
    name="samaccountname",
    style=api_client.ParameterStyle.FORM,
    schema=SamaccountnameSchema,
    explode=True,
)
request_query_directory_id = api_client.QueryParameter(
    name="directory_id",
    style=api_client.ParameterStyle.FORM,
    schema=DirectoryIdSchema,
    explode=True,
)
request_query_external_id = api_client.QueryParameter(
    name="external_id",
    style=api_client.ParameterStyle.FORM,
    schema=ExternalIdSchema,
    explode=True,
)
request_query_user_ids = api_client.QueryParameter(
    name="user_ids",
    style=api_client.ParameterStyle.FORM,
    schema=UserIdsSchema,
    explode=True,
)
request_query_custom_attributes_attribute_name = api_client.QueryParameter(
    name="custom_attributes.{attribute_name}",
    style=api_client.ParameterStyle.FORM,
    schema=CustomAttributesAttributeNameSchema,
    explode=True,
)
request_query_fields = api_client.QueryParameter(
    name="fields",
    style=api_client.ParameterStyle.FORM,
    schema=FieldsSchema,
    explode=True,
)
request_query_app_id = api_client.QueryParameter(
    name="app_id",
    style=api_client.ParameterStyle.FORM,
    schema=AppIdSchema,
    explode=True,
)
_auth = [
    'OAuth2',
]


class SchemaFor200ResponseBodyApplicationJson(
    schemas.ListSchema
):


    class MetaOapg:
        
        @staticmethod
        def items() -> typing.Type['User']:
            return User

    def __new__(
        cls,
        _arg: typing.Union[typing.Tuple['User'], typing.List['User']],
        _configuration: typing.Optional[schemas.Configuration] = None,
    ) -> 'SchemaFor200ResponseBodyApplicationJson':
        return super().__new__(
            cls,
            _arg,
            _configuration=_configuration,
        )

    def __getitem__(self, i: int) -> 'User':
        return super().__getitem__(i)


@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),
    },
)
SchemaFor400ResponseBodyApplicationJson = Error


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


_response_for_400 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor400,
    content={
        'application/json': api_client.MediaType(
            schema=SchemaFor400ResponseBodyApplicationJson),
    },
)
SchemaFor401ResponseBodyApplicationJson = Error


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


_response_for_401 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor401,
    content={
        'application/json': api_client.MediaType(
            schema=SchemaFor401ResponseBodyApplicationJson),
    },
)
SchemaFor422ResponseBodyApplicationJson = Error


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


_response_for_422 = api_client.OpenApiResponse(
    response_cls=ApiResponseFor422,
    content={
        'application/json': api_client.MediaType(
            schema=SchemaFor422ResponseBodyApplicationJson),
    },
)
_status_code_to_response = {
    '200': _response_for_200,
    '400': _response_for_400,
    '401': _response_for_401,
    '422': _response_for_422,
}
_all_accept_content_types = (
    'application/json',
)


class BaseApi(api_client.Api):
    @typing.overload
    def _list_users2_oapg(
        self,
        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: typing_extensions.Literal[False] = ...,
    ) -> typing.Union[
        ApiResponseFor200,
    ]: ...

    @typing.overload
    def _list_users2_oapg(
        self,
        skip_deserialization: typing_extensions.Literal[True],
        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,
    ) -> api_client.ApiResponseWithoutDeserialization: ...

    @typing.overload
    def _list_users2_oapg(
        self,
        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 = ...,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization,
    ]: ...

    def _list_users2_oapg(
        self,
        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,
    ):
        """
        List Users
        :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_limit,
            request_query_page,
            request_query_cursor,
            request_query_created_since,
            request_query_created_until,
            request_query_updated_since,
            request_query_updated_until,
            request_query_last_login_since,
            request_query_last_login_until,
            request_query_firstname,
            request_query_lastname,
            request_query_email,
            request_query_username,
            request_query_samaccountname,
            request_query_directory_id,
            request_query_external_id,
            request_query_user_ids,
            request_query_custom_attributes_attribute_name,
            request_query_fields,
            request_query_app_id,
        ):
            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(
                status=response.status,
                reason=response.reason,
                api_response=api_response
            )

        return api_response


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

    @typing.overload
    def list_users2(
        self,
        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: typing_extensions.Literal[False] = ...,
    ) -> typing.Union[
        ApiResponseFor200,
    ]: ...

    @typing.overload
    def list_users2(
        self,
        skip_deserialization: typing_extensions.Literal[True],
        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,
    ) -> api_client.ApiResponseWithoutDeserialization: ...

    @typing.overload
    def list_users2(
        self,
        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 = ...,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization,
    ]: ...

    def list_users2(
        self,
        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,
    ):
        return self._list_users2_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

    @typing.overload
    def get(
        self,
        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: typing_extensions.Literal[False] = ...,
    ) -> typing.Union[
        ApiResponseFor200,
    ]: ...

    @typing.overload
    def get(
        self,
        skip_deserialization: typing_extensions.Literal[True],
        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,
    ) -> api_client.ApiResponseWithoutDeserialization: ...

    @typing.overload
    def get(
        self,
        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 = ...,
    ) -> typing.Union[
        ApiResponseFor200,
        api_client.ApiResponseWithoutDeserialization,
    ]: ...

    def get(
        self,
        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,
    ):
        return self._list_users2_oapg(
            query_params=query_params,
            accept_content_types=accept_content_types,
            stream=stream,
            timeout=timeout,
            skip_deserialization=skip_deserialization
        )


