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

#include "pybase.h"
#include "py.Windows.System.Threading.Core.h"


namespace py::cpp::Windows::System::Threading::Core
{
    struct module_state
    {
        PyTypeObject* type_PreallocatedWorkItem;
        PyTypeObject* type_SignalNotifier;
    };

    // ----- PreallocatedWorkItem class --------------------
    static constexpr const char* const type_name_PreallocatedWorkItem = "PreallocatedWorkItem";

    static PyObject* _new_PreallocatedWorkItem(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<winrt::Windows::System::Threading::WorkItemHandler>(args, 0);

                winrt::Windows::System::Threading::Core::PreallocatedWorkItem instance{ param0 };
                return py::wrap(instance, type);
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 2)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::WorkItemHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::WorkItemPriority>(args, 1);

                winrt::Windows::System::Threading::Core::PreallocatedWorkItem instance{ param0, param1 };
                return py::wrap(instance, type);
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 3)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::WorkItemHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::WorkItemPriority>(args, 1);
                auto param2 = py::convert_to<winrt::Windows::System::Threading::WorkItemOptions>(args, 2);

                winrt::Windows::System::Threading::Core::PreallocatedWorkItem instance{ param0, param1, param2 };
                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_PreallocatedWorkItem(py::wrapper::Windows::System::Threading::Core::PreallocatedWorkItem* self) noexcept
    {
        auto tp = Py_TYPE(self);

        if (PyType_IS_GC(tp))
        {
            PyObject_GC_UnTrack(self);
        }

        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* PreallocatedWorkItem_RunAsync(py::wrapper::Windows::System::Threading::Core::PreallocatedWorkItem* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.PreallocatedWorkItem", L"RunAsync", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

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

    static PyObject* _assign_array_PreallocatedWorkItem(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::System::Threading::Core::PreallocatedWorkItem>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_PreallocatedWorkItem(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::System::Threading::Core::PreallocatedWorkItem>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_PreallocatedWorkItem[] = {
        { "run_async", reinterpret_cast<PyCFunction>(PreallocatedWorkItem_RunAsync), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_PreallocatedWorkItem, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_PreallocatedWorkItem), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_PreallocatedWorkItem[] = {
        { }
    };

    static PyType_Slot _type_slots_PreallocatedWorkItem[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_PreallocatedWorkItem) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_PreallocatedWorkItem) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_PreallocatedWorkItem) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_PreallocatedWorkItem) },
        { },
    };

    static PyType_Spec type_spec_PreallocatedWorkItem =
    {
        "_winsdk_Windows_System_Threading_Core.PreallocatedWorkItem",
        sizeof(py::wrapper::Windows::System::Threading::Core::PreallocatedWorkItem),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_PreallocatedWorkItem
    };

    // ----- SignalNotifier class --------------------
    static constexpr const char* const type_name_SignalNotifier = "SignalNotifier";

    static PyObject* _new_SignalNotifier(PyTypeObject* type, PyObject* args, PyObject* kwds) noexcept
    {
        py::set_invalid_activation_error(type_name_SignalNotifier);
        return nullptr;
    }

    static void _dealloc_SignalNotifier(py::wrapper::Windows::System::Threading::Core::SignalNotifier* self) noexcept
    {
        auto tp = Py_TYPE(self);

        if (PyType_IS_GC(tp))
        {
            PyObject_GC_UnTrack(self);
        }

        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* SignalNotifier_AttachToEvent(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"AttachToEvent", 2))
            {
                py::set_arg_count_version_error(2);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::Core::SignalHandler>(args, 1);

                return py::convert(winrt::Windows::System::Threading::Core::SignalNotifier::AttachToEvent(param0, param1));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 3)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"AttachToEvent", 3))
            {
                py::set_arg_count_version_error(3);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::Core::SignalHandler>(args, 1);
                auto param2 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 2);

                return py::convert(winrt::Windows::System::Threading::Core::SignalNotifier::AttachToEvent(param0, param1, param2));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SignalNotifier_AttachToSemaphore(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"AttachToSemaphore", 2))
            {
                py::set_arg_count_version_error(2);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::Core::SignalHandler>(args, 1);

                return py::convert(winrt::Windows::System::Threading::Core::SignalNotifier::AttachToSemaphore(param0, param1));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 3)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"AttachToSemaphore", 3))
            {
                py::set_arg_count_version_error(3);
                return nullptr;
            }

            try
            {
                auto param0 = py::convert_to<winrt::hstring>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::System::Threading::Core::SignalHandler>(args, 1);
                auto param2 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 2);

                return py::convert(winrt::Windows::System::Threading::Core::SignalNotifier::AttachToSemaphore(param0, param1, param2));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* SignalNotifier_Enable(py::wrapper::Windows::System::Threading::Core::SignalNotifier* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"Enable", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

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

    static PyObject* SignalNotifier_Terminate(py::wrapper::Windows::System::Threading::Core::SignalNotifier* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.System.Threading.Core.SignalNotifier", L"Terminate", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

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

    static PyObject* _assign_array_SignalNotifier(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::System::Threading::Core::SignalNotifier>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_SignalNotifier(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::System::Threading::Core::SignalNotifier>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_SignalNotifier[] = {
        { "attach_to_event", reinterpret_cast<PyCFunction>(SignalNotifier_AttachToEvent), METH_VARARGS | METH_STATIC, nullptr },
        { "attach_to_semaphore", reinterpret_cast<PyCFunction>(SignalNotifier_AttachToSemaphore), METH_VARARGS | METH_STATIC, nullptr },
        { "enable", reinterpret_cast<PyCFunction>(SignalNotifier_Enable), METH_VARARGS, nullptr },
        { "terminate", reinterpret_cast<PyCFunction>(SignalNotifier_Terminate), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_SignalNotifier, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_SignalNotifier), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_SignalNotifier[] = {
        { }
    };

    static PyType_Slot _type_slots_SignalNotifier[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_SignalNotifier) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_SignalNotifier) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_SignalNotifier) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_SignalNotifier) },
        { },
    };

    static PyType_Spec type_spec_SignalNotifier =
    {
        "_winsdk_Windows_System_Threading_Core.SignalNotifier",
        sizeof(py::wrapper::Windows::System::Threading::Core::SignalNotifier),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_SignalNotifier
    };

    // ----- Windows.System.Threading.Core Initialization --------------------
    PyDoc_STRVAR(module_doc, "Windows::System::Threading::Core");

    static PyMethodDef module_methods[] = {
        {}};


    static int module_traverse(PyObject* module, visitproc visit, void* arg) noexcept
    {
        auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));

        if (!state)
        {
            return 0;
        }

        Py_VISIT(state->type_PreallocatedWorkItem);
        Py_VISIT(state->type_SignalNotifier);

        return 0;
    }

    static int module_clear(PyObject* module) noexcept
    {
        auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));

        if (!state)
        {
            return 0;
        }

        Py_CLEAR(state->type_PreallocatedWorkItem);
        Py_CLEAR(state->type_SignalNotifier);

        return 0;
    }


    static PyModuleDef module_def
        = {PyModuleDef_HEAD_INIT,
           "_winsdk_Windows_System_Threading_Core",
           module_doc,
           sizeof(module_state),
           module_methods,
           nullptr,
           module_traverse,
           module_clear,
           nullptr};

} // py::cpp::Windows::System::Threading::Core

PyMODINIT_FUNC PyInit__winsdk_Windows_System_Threading_Core(void) noexcept
{
    using namespace py::cpp::Windows::System::Threading::Core;

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

    if (!module)
    {
        return nullptr;
    }

    auto object_type = py::get_python_type<py::Object>();
    if (!object_type)
    {
        return nullptr;
    }

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

    if (!bases)
    {
        return nullptr;
    }

    py::pyobj_handle collections_abc_module{PyImport_ImportModule("collections.abc")};

    if (!collections_abc_module)
    {
        return nullptr;
    }

    py::pyobj_handle sequence_type{PyObject_GetAttrString(collections_abc_module.get(), "Sequence")};

    if (!sequence_type)
    {
        return nullptr;
    }

    py::pyobj_handle sequence_bases{PyTuple_Pack(2, object_type, sequence_type.get())};

    if (!sequence_bases)
    {
        return nullptr;
    }

    py::pyobj_handle mutable_sequence_type{PyObject_GetAttrString(collections_abc_module.get(), "MutableSequence")};

    if (!mutable_sequence_type)
    {
        return nullptr;
    }

    py::pyobj_handle mutable_sequence_bases{PyTuple_Pack(2, object_type, mutable_sequence_type.get())};

    if (!mutable_sequence_bases)
    {
        return nullptr;
    }

    py::pyobj_handle mapping_type{PyObject_GetAttrString(collections_abc_module.get(), "Mapping")};

    if (!mapping_type)
    {
        return nullptr;
    }

    py::pyobj_handle mapping_bases{PyTuple_Pack(2, object_type, mapping_type.get())};

    if (!mapping_bases)
    {
        return nullptr;
    }

    py::pyobj_handle mutable_mapping_type{PyObject_GetAttrString(collections_abc_module.get(), "MutableMapping")};

    if (!mutable_mapping_type)
    {
        return nullptr;
    }

    py::pyobj_handle mutable_mapping_bases{PyTuple_Pack(2, object_type, mutable_mapping_type.get())};

    if (!mutable_mapping_bases)
    {
        return nullptr;
    }

    auto state = reinterpret_cast<module_state*>(PyModule_GetState(module.get()));
    assert(state);

    state->type_PreallocatedWorkItem = py::register_python_type(module.get(), type_name_PreallocatedWorkItem, &type_spec_PreallocatedWorkItem, bases.get(), nullptr);
    if (!state->type_PreallocatedWorkItem)
    {
        return nullptr;
    }

    state->type_SignalNotifier = py::register_python_type(module.get(), type_name_SignalNotifier, &type_spec_SignalNotifier, bases.get(), nullptr);
    if (!state->type_SignalNotifier)
    {
        return nullptr;
    }


    return module.detach();
}

PyTypeObject* py::winrt_type<winrt::Windows::System::Threading::Core::PreallocatedWorkItem>::get_python_type() noexcept {
    using namespace py::cpp::Windows::System::Threading::Core;

    PyObject* module = PyState_FindModule(&module_def);

    if (!module) {
        PyErr_SetString(PyExc_RuntimeError, "could not find module for Windows::System::Threading::Core");
        return nullptr;
    }

    auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));
    assert(state);

    auto python_type = state->type_PreallocatedWorkItem;

    if (!python_type) {
        PyErr_SetString(PyExc_RuntimeError, "type winrt::Windows::System::Threading::Core::PreallocatedWorkItem is not registered");
        return nullptr;
    }

    return python_type;
}

PyTypeObject* py::winrt_type<winrt::Windows::System::Threading::Core::SignalNotifier>::get_python_type() noexcept {
    using namespace py::cpp::Windows::System::Threading::Core;

    PyObject* module = PyState_FindModule(&module_def);

    if (!module) {
        PyErr_SetString(PyExc_RuntimeError, "could not find module for Windows::System::Threading::Core");
        return nullptr;
    }

    auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));
    assert(state);

    auto python_type = state->type_SignalNotifier;

    if (!python_type) {
        PyErr_SetString(PyExc_RuntimeError, "type winrt::Windows::System::Threading::Core::SignalNotifier is not registered");
        return nullptr;
    }

    return python_type;
}
