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

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

PyTypeObject* py::winrt_type<winrt::Windows::System::Threading::ThreadPool>::python_type;
PyTypeObject* py::winrt_type<winrt::Windows::System::Threading::ThreadPoolTimer>::python_type;

namespace py::cpp::Windows::System::Threading
{
    // ----- ThreadPool class --------------------
    constexpr const char* const _type_name_ThreadPool = "ThreadPool";

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

    static PyObject* ThreadPool_RunAsync(PyObject* /*unused*/, PyObject* args) noexcept
    {
        Py_ssize_t arg_count = PyTuple_Size(args);

        if (arg_count == 1)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::WorkItemHandler>(args, 0);

                return py::convert(winrt::Windows::System::Threading::ThreadPool::RunAsync(param0));
            }
            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);

                return py::convert(winrt::Windows::System::Threading::ThreadPool::RunAsync(param0, param1));
            }
            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);

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

    static PyMethodDef _methods_ThreadPool[] = {
        { "run_async", reinterpret_cast<PyCFunction>(ThreadPool_RunAsync), METH_VARARGS | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_ThreadPool[] = {
        { }
    };

    static PyType_Slot _type_slots_ThreadPool[] = 
    {
        { Py_tp_new, _new_ThreadPool },
        { Py_tp_methods, _methods_ThreadPool },
        { Py_tp_getset, _getset_ThreadPool },
        { },
    };

    static PyType_Spec _type_spec_ThreadPool =
    {
        "_winsdk_Windows_System_Threading.ThreadPool",
        0,
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ThreadPool
    };

    // ----- ThreadPoolTimer class --------------------
    constexpr const char* const _type_name_ThreadPoolTimer = "ThreadPoolTimer";

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

    static void _dealloc_ThreadPoolTimer(py::wrapper::Windows::System::Threading::ThreadPoolTimer* self)
    {
        auto hash_value = std::hash<winrt::Windows::Foundation::IInspectable>{}(self->obj);
        py::wrapped_instance(hash_value, nullptr);
        self->obj = nullptr;
    }

    static PyObject* ThreadPoolTimer_Cancel(py::wrapper::Windows::System::Threading::ThreadPoolTimer* self, PyObject* args) noexcept
    {
        Py_ssize_t arg_count = PyTuple_Size(args);

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

    static PyObject* ThreadPoolTimer_CreatePeriodicTimer(PyObject* /*unused*/, PyObject* args) noexcept
    {
        Py_ssize_t arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::TimerElapsedHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 1);

                return py::convert(winrt::Windows::System::Threading::ThreadPoolTimer::CreatePeriodicTimer(param0, param1));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 3)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::TimerElapsedHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 1);
                auto param2 = py::convert_to<winrt::Windows::System::Threading::TimerDestroyedHandler>(args, 2);

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

    static PyObject* ThreadPoolTimer_CreateTimer(PyObject* /*unused*/, PyObject* args) noexcept
    {
        Py_ssize_t arg_count = PyTuple_Size(args);

        if (arg_count == 2)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::TimerElapsedHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 1);

                return py::convert(winrt::Windows::System::Threading::ThreadPoolTimer::CreateTimer(param0, param1));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 3)
        {
            try
            {
                auto param0 = py::convert_to<winrt::Windows::System::Threading::TimerElapsedHandler>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::Foundation::TimeSpan>(args, 1);
                auto param2 = py::convert_to<winrt::Windows::System::Threading::TimerDestroyedHandler>(args, 2);

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

    static PyObject* ThreadPoolTimer_get_Delay(py::wrapper::Windows::System::Threading::ThreadPoolTimer* self, void* /*unused*/) noexcept
    {
        try
        {
            return py::convert(self->obj.Delay());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* ThreadPoolTimer_get_Period(py::wrapper::Windows::System::Threading::ThreadPoolTimer* self, void* /*unused*/) noexcept
    {
        try
        {
            return py::convert(self->obj.Period());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _from_ThreadPoolTimer(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::ThreadPoolTimer>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_ThreadPoolTimer[] = {
        { "cancel", reinterpret_cast<PyCFunction>(ThreadPoolTimer_Cancel), METH_VARARGS, nullptr },
        { "create_periodic_timer", reinterpret_cast<PyCFunction>(ThreadPoolTimer_CreatePeriodicTimer), METH_VARARGS | METH_STATIC, nullptr },
        { "create_timer", reinterpret_cast<PyCFunction>(ThreadPoolTimer_CreateTimer), METH_VARARGS | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_ThreadPoolTimer), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_ThreadPoolTimer[] = {
        { "delay", reinterpret_cast<getter>(ThreadPoolTimer_get_Delay), nullptr, nullptr, nullptr },
        { "period", reinterpret_cast<getter>(ThreadPoolTimer_get_Period), nullptr, nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_ThreadPoolTimer[] = 
    {
        { Py_tp_new, _new_ThreadPoolTimer },
        { Py_tp_dealloc, _dealloc_ThreadPoolTimer },
        { Py_tp_methods, _methods_ThreadPoolTimer },
        { Py_tp_getset, _getset_ThreadPoolTimer },
        { },
    };

    static PyType_Spec _type_spec_ThreadPoolTimer =
    {
        "_winsdk_Windows_System_Threading.ThreadPoolTimer",
        sizeof(py::wrapper::Windows::System::Threading::ThreadPoolTimer),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_ThreadPoolTimer
    };

    // ----- Windows.System.Threading Initialization --------------------
    static int module_exec(PyObject* module) noexcept
    {
        try
        {
            py::pyobj_handle bases { PyTuple_Pack(1, py::winrt_type<py::Object>::python_type) };

            py::winrt_type<winrt::Windows::System::Threading::ThreadPool>::python_type = py::register_python_type(module, _type_name_ThreadPool, &_type_spec_ThreadPool, nullptr);
            py::winrt_type<winrt::Windows::System::Threading::ThreadPoolTimer>::python_type = py::register_python_type(module, _type_name_ThreadPoolTimer, &_type_spec_ThreadPoolTimer, bases.get());

            return 0;
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyModuleDef_Slot module_slots[] = {{Py_mod_exec, module_exec}, {}};

    PyDoc_STRVAR(module_doc, "Windows.System.Threading");

    static PyModuleDef module_def
        = {PyModuleDef_HEAD_INIT,
           "_winsdk_Windows_System_Threading",
           module_doc,
           0,
           nullptr,
           module_slots,
           nullptr,
           nullptr,
           nullptr};
} // py::cpp::Windows::System::Threading

PyMODINIT_FUNC
PyInit__winsdk_Windows_System_Threading (void) noexcept
{
    return PyModuleDef_Init(&py::cpp::Windows::System::Threading::module_def);
}
