#
# Autogenerated by Thrift for shared.thrift
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#  @generated
#
from libc.stdint cimport (
    int8_t as cint8_t,
    int16_t as cint16_t,
    int32_t as cint32_t,
    int64_t as cint64_t,
)
from libcpp.memory cimport shared_ptr, make_shared, unique_ptr
from libcpp.string cimport string
from libcpp cimport bool as cbool
from cpython cimport bool as pbool
from libcpp.vector cimport vector
from libcpp.set cimport set as cset
from libcpp.map cimport map as cmap
from libcpp.utility cimport move as cmove
from cython.operator cimport dereference as deref, typeid
from cpython.ref cimport PyObject
from thrift.py3.client cimport cRequestChannel_ptr, makeClientWrapper, cClientWrapper
from thrift.py3.exceptions cimport try_make_shared_exception
from thrift.python.exceptions cimport create_py_exception
from folly cimport cFollyTry, cFollyUnit, c_unit
from folly.cast cimport down_cast_ptr
from libcpp.typeinfo cimport type_info
import thrift.py3.types
cimport thrift.py3.types
from thrift.py3.types cimport make_unique
import thrift.py3.client
cimport thrift.py3.client
from thrift.python.common cimport (
    RpcOptions as __RpcOptions,
    cThriftServiceMetadataResponse as __fbthrift_cThriftServiceMetadataResponse,
    ServiceMetadata,
    MetadataBox as __MetadataBox,
)

from folly.futures cimport bridgeFutureWith
from folly.executor cimport get_executor
cimport folly.iobuf as _fbthrift_iobuf
import folly.iobuf as _fbthrift_iobuf
from folly.iobuf cimport move as move_iobuf
cimport cython

import sys
import types as _py_types
from asyncio import get_event_loop as asyncio_get_event_loop, shield as asyncio_shield, InvalidStateError as asyncio_InvalidStateError

cimport test.fixtures.another_interactions.shared.types as _test_fixtures_another_interactions_shared_types
cimport test.fixtures.another_interactions.shared.cbindings as _test_fixtures_another_interactions_shared_cbindings
import test.fixtures.another_interactions.shared.types as _test_fixtures_another_interactions_shared_types

import test.fixtures.another_interactions.shared.services_reflection as _services_reflection
cimport test.fixtures.another_interactions.shared.services_reflection as _services_reflection

from test.fixtures.another_interactions.shared.clients_wrapper cimport cInteractLocallyAsyncClient, cInteractLocallyClientWrapper
from test.fixtures.another_interactions.shared.clients_wrapper cimport cInteractLocallyClientWrapper_SharedInteractionInteractionWrapper


cdef void InteractLocally_SharedInteraction_init_callback(
    cFollyTry[cint32_t]&& result,
    PyObject* userdata
) noexcept:
    client, pyfuture, options = <object> userdata  
    if result.hasException():
        pyfuture.set_exception(create_py_exception(result.exception(), <__RpcOptions>options))
    else:
        try:
            pyfuture.set_result(result.value())
        except Exception as ex:
            pyfuture.set_exception(ex.with_traceback(None))

cdef void InteractLocally_SharedInteraction_do_something_callback(
    cFollyTry[_test_fixtures_another_interactions_shared_cbindings.cDoSomethingResult]&& result,
    PyObject* userdata
) noexcept:
    client, pyfuture, options = <object> userdata  
    if result.hasException():
        pyfuture.set_exception(create_py_exception(result.exception(), <__RpcOptions>options))
    else:
        try:
            pyfuture.set_result(_test_fixtures_another_interactions_shared_types.DoSomethingResult._create_FBTHRIFT_ONLY_DO_NOT_USE(make_shared[_test_fixtures_another_interactions_shared_cbindings.cDoSomethingResult](cmove(result.value()))))
        except Exception as ex:
            pyfuture.set_exception(ex.with_traceback(None))

cdef void InteractLocally_SharedInteraction_tear_down_callback(
    cFollyTry[cFollyUnit]&& result,
    PyObject* userdata
) noexcept:
    client, pyfuture, options = <object> userdata  
    if result.hasException():
        pyfuture.set_exception(create_py_exception(result.exception(), <__RpcOptions>options))
    else:
        try:
            pyfuture.set_result(None)
        except Exception as ex:
            pyfuture.set_exception(ex.with_traceback(None))


cdef object _InteractLocally_annotations = _py_types.MappingProxyType({
})


@cython.auto_pickle(False)
cdef class InteractLocally(thrift.py3.client.Client):
    annotations = _InteractLocally_annotations

    cdef const type_info* _typeid(InteractLocally self):
        return &typeid(cInteractLocallyAsyncClient)

    cdef bind_client(InteractLocally self, cRequestChannel_ptr&& channel):
        self._client = makeClientWrapper[cInteractLocallyAsyncClient, cInteractLocallyClientWrapper](
            cmove(channel)
        )


    def createSharedInteraction(
            InteractLocally self
    ):
        interaction = InteractLocally_SharedInteraction()
        bridgeFutureWith[unique_ptr[cClientWrapper]](
            interaction._executor,
            down_cast_ptr[cInteractLocallyClientWrapper, cClientWrapper](self._client.get()).createSharedInteraction(),
            thrift.py3.client.interactions_callback,
            <PyObject *> interaction
        )
        return interaction

    async def async_createSharedInteraction(
            InteractLocally self
    ):
        return self.createSharedInteraction()

    @classmethod
    def __get_reflection__(cls):
        return _services_reflection.get_reflection__InteractLocally(for_clients=True)

    @staticmethod
    def __get_metadata__():
        cdef __fbthrift_cThriftServiceMetadataResponse response
        ServiceMetadata[_services_reflection.cInteractLocallySvIf].gen(response)
        return __MetadataBox.box(cmove(deref(response.metadata_ref())))

    @staticmethod
    def __get_thrift_name__():
        return "shared.InteractLocally"

@cython.auto_pickle(False)
cdef class InteractLocally_SharedInteraction(thrift.py3.client.Client):

    @cython.always_allow_keywords(True)
    def init(
            InteractLocally_SharedInteraction self,
            __RpcOptions rpc_options=None
    ):
        if rpc_options is None:
            rpc_options = <__RpcOptions>__RpcOptions.__new__(__RpcOptions)
        self._check_connect_future()
        __loop = asyncio_get_event_loop()
        __future = __loop.create_future()
        __userdata = (self, __future, rpc_options)
        bridgeFutureWith[cint32_t](
            self._executor,
            down_cast_ptr[cInteractLocallyClientWrapper_SharedInteractionInteractionWrapper, cClientWrapper](self._client.get()).init(rpc_options._cpp_obj, 
            ),
            InteractLocally_SharedInteraction_init_callback,
            <PyObject *> __userdata
        )
        return asyncio_shield(__future)

    @cython.always_allow_keywords(True)
    def do_something(
            InteractLocally_SharedInteraction self,
            __RpcOptions rpc_options=None
    ):
        if rpc_options is None:
            rpc_options = <__RpcOptions>__RpcOptions.__new__(__RpcOptions)
        self._check_connect_future()
        __loop = asyncio_get_event_loop()
        __future = __loop.create_future()
        __userdata = (self, __future, rpc_options)
        bridgeFutureWith[_test_fixtures_another_interactions_shared_cbindings.cDoSomethingResult](
            self._executor,
            down_cast_ptr[cInteractLocallyClientWrapper_SharedInteractionInteractionWrapper, cClientWrapper](self._client.get()).do_something(rpc_options._cpp_obj, 
            ),
            InteractLocally_SharedInteraction_do_something_callback,
            <PyObject *> __userdata
        )
        return asyncio_shield(__future)

    @cython.always_allow_keywords(True)
    def tear_down(
            InteractLocally_SharedInteraction self,
            __RpcOptions rpc_options=None
    ):
        if rpc_options is None:
            rpc_options = <__RpcOptions>__RpcOptions.__new__(__RpcOptions)
        self._check_connect_future()
        __loop = asyncio_get_event_loop()
        __future = __loop.create_future()
        __userdata = (self, __future, rpc_options)
        bridgeFutureWith[cFollyUnit](
            self._executor,
            down_cast_ptr[cInteractLocallyClientWrapper_SharedInteractionInteractionWrapper, cClientWrapper](self._client.get()).tear_down(rpc_options._cpp_obj, 
            ),
            InteractLocally_SharedInteraction_tear_down_callback,
            <PyObject *> __userdata
        )
        return asyncio_shield(__future)

