// WARNING: Please don't edit this file. It was generated by Python/WinRT v2.0.0-beta.1

#include "py.Windows.Devices.Spi.Provider.h"


namespace py::cpp::Windows::Devices::Spi::Provider
{
    // ----- ProviderSpiConnectionSettings class --------------------

    static PyObject* _new_ProviderSpiConnectionSettings(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept
    {
        if (kwds != nullptr)
        {
            py::set_invalid_kwd_args_error();
            return nullptr;
        }

        auto arg_count = PyTuple_Size(args);
        if (arg_count == 1)
        {
            try
            {
                auto param0 = py::convert_to<int32_t>(args, 0);

                winrt::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings instance{ param0 };
                return py::wrap(instance, type);
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static void _dealloc_ProviderSpiConnectionSettings(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* ProviderSpiConnectionSettings_get_SharingMode(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"SharingMode"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.SharingMode());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int ProviderSpiConnectionSettings_put_SharingMode(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"SharingMode"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return -1;
        }

        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            auto param0 = py::convert_to<winrt::Windows::Devices::Spi::Provider::ProviderSpiSharingMode>(arg);

            self->obj.SharingMode(param0);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* ProviderSpiConnectionSettings_get_Mode(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"Mode"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.Mode());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int ProviderSpiConnectionSettings_put_Mode(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"Mode"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return -1;
        }

        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            auto param0 = py::convert_to<winrt::Windows::Devices::Spi::Provider::ProviderSpiMode>(arg);

            self->obj.Mode(param0);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* ProviderSpiConnectionSettings_get_DataBitLength(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"DataBitLength"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.DataBitLength());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int ProviderSpiConnectionSettings_put_DataBitLength(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"DataBitLength"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return -1;
        }

        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            auto param0 = py::convert_to<int32_t>(arg);

            self->obj.DataBitLength(param0);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* ProviderSpiConnectionSettings_get_ClockFrequency(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"ClockFrequency"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.ClockFrequency());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int ProviderSpiConnectionSettings_put_ClockFrequency(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"ClockFrequency"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return -1;
        }

        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            auto param0 = py::convert_to<int32_t>(arg);

            self->obj.ClockFrequency(param0);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* ProviderSpiConnectionSettings_get_ChipSelectLine(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"ChipSelectLine"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.ChipSelectLine());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static int ProviderSpiConnectionSettings_put_ChipSelectLine(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings* self, PyObject* arg, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ProviderSpiConnectionSettings", L"ChipSelectLine"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return -1;
        }

        if (arg == nullptr)
        {
            PyErr_SetString(PyExc_AttributeError, "can't delete attribute");
            return -1;
        }

        try
        {
            auto param0 = py::convert_to<int32_t>(arg);

            self->obj.ChipSelectLine(param0);
            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* _assign_array_ProviderSpiConnectionSettings(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_ProviderSpiConnectionSettings(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ProviderSpiConnectionSettings[] = {
        { "_assign_array_", _assign_array_ProviderSpiConnectionSettings, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ProviderSpiConnectionSettings), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_ProviderSpiConnectionSettings[] = {
        { "sharing_mode", reinterpret_cast<getter>(ProviderSpiConnectionSettings_get_SharingMode), reinterpret_cast<setter>(ProviderSpiConnectionSettings_put_SharingMode), nullptr, nullptr },
        { "mode", reinterpret_cast<getter>(ProviderSpiConnectionSettings_get_Mode), reinterpret_cast<setter>(ProviderSpiConnectionSettings_put_Mode), nullptr, nullptr },
        { "data_bit_length", reinterpret_cast<getter>(ProviderSpiConnectionSettings_get_DataBitLength), reinterpret_cast<setter>(ProviderSpiConnectionSettings_put_DataBitLength), nullptr, nullptr },
        { "clock_frequency", reinterpret_cast<getter>(ProviderSpiConnectionSettings_get_ClockFrequency), reinterpret_cast<setter>(ProviderSpiConnectionSettings_put_ClockFrequency), nullptr, nullptr },
        { "chip_select_line", reinterpret_cast<getter>(ProviderSpiConnectionSettings_get_ChipSelectLine), reinterpret_cast<setter>(ProviderSpiConnectionSettings_put_ChipSelectLine), nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_ProviderSpiConnectionSettings[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_ProviderSpiConnectionSettings) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_ProviderSpiConnectionSettings) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_ProviderSpiConnectionSettings) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_ProviderSpiConnectionSettings) },
        { },
    };

    static PyType_Spec type_spec_ProviderSpiConnectionSettings =
    {
        "winrt._winrt_windows_devices_spi_provider.ProviderSpiConnectionSettings",
        sizeof(py::wrapper::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ProviderSpiConnectionSettings
    };

    // ----- ISpiControllerProvider interface --------------------

    static PyObject* _new_ISpiControllerProvider(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiControllerProvider>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiControllerProvider>::type_name);
        return nullptr;
    }

    static void _dealloc_ISpiControllerProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiControllerProvider* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* ISpiControllerProvider_GetDeviceProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiControllerProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 1)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiControllerProvider", L"GetDeviceProvider", 1))
            {
                py::set_arg_count_version_error(1);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<winrt::Windows::Devices::Spi::Provider::ProviderSpiConnectionSettings>(args, 0);

                return py::convert(self->obj.GetDeviceProvider(param0));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* _assign_array_ISpiControllerProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::Spi::Provider::ISpiControllerProvider>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_ISpiControllerProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::Spi::Provider::ISpiControllerProvider>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ISpiControllerProvider[] = {
        { "get_device_provider", reinterpret_cast<PyCFunction>(ISpiControllerProvider_GetDeviceProvider), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_ISpiControllerProvider, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ISpiControllerProvider), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_ISpiControllerProvider[] = {
        { }
    };

    static PyType_Slot _type_slots_ISpiControllerProvider[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_ISpiControllerProvider) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_ISpiControllerProvider) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_ISpiControllerProvider) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_ISpiControllerProvider) },
        { },
    };

    static PyType_Spec type_spec_ISpiControllerProvider =
    {
        "winrt._winrt_windows_devices_spi_provider.ISpiControllerProvider",
        sizeof(py::wrapper::Windows::Devices::Spi::Provider::ISpiControllerProvider),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ISpiControllerProvider
    };

    // ----- ISpiDeviceProvider interface --------------------

    static PyObject* _new_ISpiDeviceProvider(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiDeviceProvider>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiDeviceProvider>::type_name);
        return nullptr;
    }

    static void _dealloc_ISpiDeviceProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* ISpiDeviceProvider_Close(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Foundation.IClosable", L"Close", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

            try
            {
                self->obj.Close();
                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_Read(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 1)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"Read", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 0);

                self->obj.Read(param0);
                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_TransferFullDuplex(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"TransferFullDuplex", 1))
            {
                py::set_arg_count_version_error(1);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);
                auto param1 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 1);

                self->obj.TransferFullDuplex(param0, param1);
                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_TransferSequential(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"TransferSequential", 1))
            {
                py::set_arg_count_version_error(1);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);
                auto param1 = py::convert_to<py::pybuf_view<uint8_t, true>>(args, 1);

                self->obj.TransferSequential(param0, param1);
                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_Write(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 1)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"Write", 1))
            {
                py::set_arg_count_version_error(1);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<py::pybuf_view<uint8_t, false>>(args, 0);

                self->obj.Write(param0);
                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_get_ConnectionSettings(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"ConnectionSettings"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.ConnectionSettings());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* ISpiDeviceProvider_get_DeviceId(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Devices.Spi.Provider.ISpiDeviceProvider", L"DeviceId"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.DeviceId());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_ISpiDeviceProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::Spi::Provider::ISpiDeviceProvider>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_ISpiDeviceProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::Spi::Provider::ISpiDeviceProvider>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _enter_ISpiDeviceProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* /*unused*/) noexcept
    {
        return Py_NewRef(self);
    }

    static PyObject* _exit_ISpiDeviceProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider* self, PyObject* /*unused*/) noexcept
    {
        try
        {
            self->obj.Close();
            Py_RETURN_FALSE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ISpiDeviceProvider[] = {
        { "close", reinterpret_cast<PyCFunction>(ISpiDeviceProvider_Close), METH_VARARGS, nullptr },
        { "read", reinterpret_cast<PyCFunction>(ISpiDeviceProvider_Read), METH_VARARGS, nullptr },
        { "transfer_full_duplex", reinterpret_cast<PyCFunction>(ISpiDeviceProvider_TransferFullDuplex), METH_VARARGS, nullptr },
        { "transfer_sequential", reinterpret_cast<PyCFunction>(ISpiDeviceProvider_TransferSequential), METH_VARARGS, nullptr },
        { "write", reinterpret_cast<PyCFunction>(ISpiDeviceProvider_Write), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_ISpiDeviceProvider, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ISpiDeviceProvider), METH_O | METH_STATIC, nullptr },
        { "__enter__", reinterpret_cast<PyCFunction>(_enter_ISpiDeviceProvider), METH_NOARGS, nullptr },
        { "__exit__",  reinterpret_cast<PyCFunction>(_exit_ISpiDeviceProvider), METH_VARARGS, nullptr },
        { }
    };

    static PyGetSetDef _getset_ISpiDeviceProvider[] = {
        { "connection_settings", reinterpret_cast<getter>(ISpiDeviceProvider_get_ConnectionSettings), nullptr, nullptr, nullptr },
        { "device_id", reinterpret_cast<getter>(ISpiDeviceProvider_get_DeviceId), nullptr, nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_ISpiDeviceProvider[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_ISpiDeviceProvider) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_ISpiDeviceProvider) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_ISpiDeviceProvider) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_ISpiDeviceProvider) },
        { },
    };

    static PyType_Spec type_spec_ISpiDeviceProvider =
    {
        "winrt._winrt_windows_devices_spi_provider.ISpiDeviceProvider",
        sizeof(py::wrapper::Windows::Devices::Spi::Provider::ISpiDeviceProvider),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ISpiDeviceProvider
    };

    // ----- ISpiProvider interface --------------------

    static PyObject* _new_ISpiProvider(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiProvider>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Devices::Spi::Provider::ISpiProvider>::type_name);
        return nullptr;
    }

    static void _dealloc_ISpiProvider(py::wrapper::Windows::Devices::Spi::Provider::ISpiProvider* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* ISpiProvider_GetControllersAsync(py::wrapper::Windows::Devices::Spi::Provider::ISpiProvider* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Devices.Spi.Provider.ISpiProvider", L"GetControllersAsync", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

            try
            {
                return py::convert(self->obj.GetControllersAsync());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* _assign_array_ISpiProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Devices::Spi::Provider::ISpiProvider>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_ISpiProvider(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        try
        {
            auto return_value = py::convert_to<winrt::Windows::Foundation::IInspectable>(arg);
            return py::convert(return_value.as<winrt::Windows::Devices::Spi::Provider::ISpiProvider>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ISpiProvider[] = {
        { "get_controllers_async", reinterpret_cast<PyCFunction>(ISpiProvider_GetControllersAsync), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_ISpiProvider, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ISpiProvider), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_ISpiProvider[] = {
        { }
    };

    static PyType_Slot _type_slots_ISpiProvider[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_ISpiProvider) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_ISpiProvider) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_ISpiProvider) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_ISpiProvider) },
        { },
    };

    static PyType_Spec type_spec_ISpiProvider =
    {
        "winrt._winrt_windows_devices_spi_provider.ISpiProvider",
        sizeof(py::wrapper::Windows::Devices::Spi::Provider::ISpiProvider),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ISpiProvider
    };

    // ----- Windows.Devices.Spi.Provider Initialization --------------------
    PyDoc_STRVAR(module_doc, "Windows::Devices::Spi::Provider");


    static PyModuleDef module_def
        = {PyModuleDef_HEAD_INIT,
           "_winrt_windows_devices_spi_provider",
           module_doc,
           0,
           nullptr,
           nullptr,
           nullptr,
           nullptr,
           nullptr};

} // py::cpp::Windows::Devices::Spi::Provider

PyMODINIT_FUNC PyInit__winrt_windows_devices_spi_provider(void) noexcept
{
    using namespace py::cpp::Windows::Devices::Spi::Provider;

    if (py::import_winrt_runtime() == -1)
    {
        return nullptr;
    }

    py::pyobj_handle module{PyModule_Create(&module_def)};

    if (!module)
    {
        return nullptr;
    }

    auto object_type = py::get_object_type();
    if (!object_type)
    {
        return nullptr;
    }

    py::pyobj_handle object_bases{PyTuple_Pack(1, object_type)};

    if (!object_bases)
    {
        return nullptr;
    }

    if (py::register_python_type(module.get(), &type_spec_ProviderSpiConnectionSettings, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }

    if (py::register_python_type(module.get(), &type_spec_ISpiControllerProvider, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }

    if (py::register_python_type(module.get(), &type_spec_ISpiDeviceProvider, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }

    if (py::register_python_type(module.get(), &type_spec_ISpiProvider, object_bases.get(), nullptr) == -1)
    {
        return nullptr;
    }


    return module.detach();
}
