// WARNING: Please don't edit this file. It was generated by Python/WinRT v3.1.0

#include "py.Windows.UI.Xaml.Printing.h"

namespace py::cpp::Windows::UI::Xaml::Printing
{
    // ----- AddPagesEventArgs class --------------------

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

        auto arg_count = PyTuple_GET_SIZE(args);
        if (arg_count == 0)
        {
            try
            {
                winrt::Windows::UI::Xaml::Printing::AddPagesEventArgs instance{};
                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_AddPagesEventArgs(py::wrapper::Windows::UI::Xaml::Printing::AddPagesEventArgs* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* AddPagesEventArgs_get_PrintTaskOptions(py::wrapper::Windows::UI::Xaml::Printing::AddPagesEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.AddPagesEventArgs", L"PrintTaskOptions");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PrintTaskOptions();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_AddPagesEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::UI::Xaml::Printing::AddPagesEventArgs>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_AddPagesEventArgs(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::UI::Xaml::Printing::AddPagesEventArgs>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_AddPagesEventArgs[] = {
        { "_assign_array_", _assign_array_AddPagesEventArgs, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_AddPagesEventArgs), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_AddPagesEventArgs[] = {
        { "print_task_options", reinterpret_cast<getter>(AddPagesEventArgs_get_PrintTaskOptions), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_AddPagesEventArgs[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_AddPagesEventArgs) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_AddPagesEventArgs) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_AddPagesEventArgs) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_AddPagesEventArgs) },
        { }};

    static PyType_Spec type_spec_AddPagesEventArgs = {
        "winrt._winrt_windows_ui_xaml_printing.AddPagesEventArgs",
        sizeof(py::wrapper::Windows::UI::Xaml::Printing::AddPagesEventArgs),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_AddPagesEventArgs};

    // ----- GetPreviewPageEventArgs class --------------------

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

        auto arg_count = PyTuple_GET_SIZE(args);
        if (arg_count == 0)
        {
            try
            {
                winrt::Windows::UI::Xaml::Printing::GetPreviewPageEventArgs instance{};
                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_GetPreviewPageEventArgs(py::wrapper::Windows::UI::Xaml::Printing::GetPreviewPageEventArgs* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* GetPreviewPageEventArgs_get_PageNumber(py::wrapper::Windows::UI::Xaml::Printing::GetPreviewPageEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.GetPreviewPageEventArgs", L"PageNumber");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PageNumber();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_GetPreviewPageEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::UI::Xaml::Printing::GetPreviewPageEventArgs>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_GetPreviewPageEventArgs(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::UI::Xaml::Printing::GetPreviewPageEventArgs>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_GetPreviewPageEventArgs[] = {
        { "_assign_array_", _assign_array_GetPreviewPageEventArgs, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_GetPreviewPageEventArgs), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_GetPreviewPageEventArgs[] = {
        { "page_number", reinterpret_cast<getter>(GetPreviewPageEventArgs_get_PageNumber), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_GetPreviewPageEventArgs[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_GetPreviewPageEventArgs) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_GetPreviewPageEventArgs) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_GetPreviewPageEventArgs) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_GetPreviewPageEventArgs) },
        { }};

    static PyType_Spec type_spec_GetPreviewPageEventArgs = {
        "winrt._winrt_windows_ui_xaml_printing.GetPreviewPageEventArgs",
        sizeof(py::wrapper::Windows::UI::Xaml::Printing::GetPreviewPageEventArgs),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_GetPreviewPageEventArgs};

    // ----- PaginateEventArgs class --------------------

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

        auto arg_count = PyTuple_GET_SIZE(args);
        if (arg_count == 0)
        {
            try
            {
                winrt::Windows::UI::Xaml::Printing::PaginateEventArgs instance{};
                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_PaginateEventArgs(py::wrapper::Windows::UI::Xaml::Printing::PaginateEventArgs* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* PaginateEventArgs_get_CurrentPreviewPageNumber(py::wrapper::Windows::UI::Xaml::Printing::PaginateEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.PaginateEventArgs", L"CurrentPreviewPageNumber");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.CurrentPreviewPageNumber();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PaginateEventArgs_get_PrintTaskOptions(py::wrapper::Windows::UI::Xaml::Printing::PaginateEventArgs* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.PaginateEventArgs", L"PrintTaskOptions");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.PrintTaskOptions();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_PaginateEventArgs(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::UI::Xaml::Printing::PaginateEventArgs>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_PaginateEventArgs(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::UI::Xaml::Printing::PaginateEventArgs>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_PaginateEventArgs[] = {
        { "_assign_array_", _assign_array_PaginateEventArgs, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_PaginateEventArgs), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_PaginateEventArgs[] = {
        { "current_preview_page_number", reinterpret_cast<getter>(PaginateEventArgs_get_CurrentPreviewPageNumber), nullptr, nullptr, nullptr },
        { "print_task_options", reinterpret_cast<getter>(PaginateEventArgs_get_PrintTaskOptions), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_PaginateEventArgs[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_PaginateEventArgs) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_PaginateEventArgs) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_PaginateEventArgs) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_PaginateEventArgs) },
        { }};

    static PyType_Spec type_spec_PaginateEventArgs = {
        "winrt._winrt_windows_ui_xaml_printing.PaginateEventArgs",
        sizeof(py::wrapper::Windows::UI::Xaml::Printing::PaginateEventArgs),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_PaginateEventArgs};

    // ----- PrintDocument class --------------------

    struct PyWinrtPrintDocument;
    using BasePyWinrtPrintDocument = winrt::Windows::UI::Xaml::Printing::PrintDocumentT<PyWinrtPrintDocument, py::IPywinrtObject>;

    struct PyWinrtPrintDocument : py::py_obj_ref, BasePyWinrtPrintDocument
    {
        PyWinrtPrintDocument(PyObject* py_obj) : py::py_obj_ref(py_obj), BasePyWinrtPrintDocument() {}

        int32_t __stdcall GetPyObject(PyObject*& obj) override
        {
            obj = py::py_obj_ref::get_py_obj();
            return 0;
        }

        int32_t __stdcall GetComposableInner(winrt::Windows::Foundation::IInspectable& inner) override
        {
            inner = m_inner;
            return winrt::impl::error_ok;
        }

        static void toggle_reference(PyWinrtPrintDocument* instance, bool is_last_reference)
        {
            py::py_obj_ref::toggle_reference(instance, is_last_reference);
        }

        int32_t query_interface_tearoff(winrt::guid const& id, void** result) const noexcept override
        {
            return py::py_obj_ref::query_interface_tearoff(id, result);
        }

        std::vector<winrt::guid> get_iids_tearoff() const noexcept override
        {
            return py::py_obj_ref::get_iids_tearoff();
        }
    };

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

        auto arg_count = PyTuple_GET_SIZE(args);

        auto self_type = get_python_type_for<winrt::Windows::UI::Xaml::Printing::PrintDocument>();
        if (!self_type)
        {
            return nullptr;
        }

        if (arg_count == 0)
        {
            try
            {
                if (type != self_type)
                {
                    py::pyobj_handle self{type->tp_alloc(type, 0)};
                    if (!self)
                    {
                        return nullptr;
                    }

                    std::construct_at(&reinterpret_cast<py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>*>(self.get())->obj, nullptr);

                    auto obj_impl = winrt::make_self<PyWinrtPrintDocument>(self.get());

                    auto obj = py::make_py_obj<PyWinrtPrintDocument>(obj_impl, type, self.get());
                    if (!obj)
                    {
                        return nullptr;
                    }

                    reinterpret_cast<py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>*>(self.get())->obj = std::move(obj);

                    return self.detach();
                }

                winrt::Windows::UI::Xaml::Printing::PrintDocument instance{};
                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_PrintDocument(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* PrintDocument_AddPage(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 1)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"AddPage", 1);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(1);
                    return nullptr;
                }

                auto param0 = py::convert_to<winrt::Windows::UI::Xaml::UIElement>(args, 0);

                {
                    auto _gil = release_gil();
                    self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().AddPage(param0);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* PrintDocument_AddPagesComplete(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"AddPagesComplete", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                {
                    auto _gil = release_gil();
                    self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().AddPagesComplete();
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* PrintDocument_InvalidatePreview(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 0)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"InvalidatePreview", 0);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(0);
                    return nullptr;
                }

                {
                    auto _gil = release_gil();
                    self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().InvalidatePreview();
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* PrintDocument_SetPreviewPage(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"SetPreviewPage", 2);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(2);
                    return nullptr;
                }

                auto param0 = py::convert_to<int32_t>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::UI::Xaml::UIElement>(args, 1);

                {
                    auto _gil = release_gil();
                    self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().SetPreviewPage(param0, param1);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* PrintDocument_SetPreviewPageCount(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_GET_SIZE(args);

        if (arg_count == 2)
        {
            try
            {
                static std::optional<bool> is_overload_present{};

                if (!is_overload_present.has_value())
                {
                    is_overload_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"SetPreviewPageCount", 2);
                }

                if (!is_overload_present.value())
                {
                    py::set_arg_count_version_error(2);
                    return nullptr;
                }

                auto param0 = py::convert_to<int32_t>(args, 0);
                auto param1 = py::convert_to<winrt::Windows::UI::Xaml::Printing::PreviewPageCountType>(args, 1);

                {
                    auto _gil = release_gil();
                    self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().SetPreviewPageCount(param0, param1);
                }

                Py_RETURN_NONE;
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* PrintDocument_get_DocumentSource(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"DocumentSource");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().DocumentSource();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_get_DocumentSourceProperty(PyObject* /*unused*/, void* /*unused*/) noexcept
    {
        try
        {
            static std::optional<bool> is_property_present{};

            if (!is_property_present.has_value())
            {
                is_property_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"DocumentSourceProperty");
            }

            if (!is_property_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
                return nullptr;
            }

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return winrt::Windows::UI::Xaml::Printing::PrintDocument::DocumentSourceProperty();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_add_AddPages(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"AddPages");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::Windows::UI::Xaml::Printing::AddPagesEventHandler>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().AddPages(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_remove_AddPages(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"AddPages");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::event_token>(arg);

            {
                auto _gil = release_gil();
                self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().AddPages(param0);
            }

            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_add_GetPreviewPage(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"GetPreviewPage");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::Windows::UI::Xaml::Printing::GetPreviewPageEventHandler>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().GetPreviewPage(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_remove_GetPreviewPage(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"GetPreviewPage");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::event_token>(arg);

            {
                auto _gil = release_gil();
                self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().GetPreviewPage(param0);
            }

            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_add_Paginate(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"Paginate");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::Windows::UI::Xaml::Printing::PaginateEventHandler>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().Paginate(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PrintDocument_remove_Paginate(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>* self, PyObject* arg) noexcept
    {
        try
        {
            static std::optional<bool> is_event_present{};

            if (!is_event_present.has_value())
            {
                is_event_present = winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.UI.Xaml.Printing.PrintDocument", L"Paginate");
            }

            if (!is_event_present.value())
            {
                PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
                return nullptr;
            }

            auto param0 = py::convert_to<winrt::event_token>(arg);

            {
                auto _gil = release_gil();
                self->obj.try_as<winrt::Windows::UI::Xaml::Printing::PrintDocument>().Paginate(param0);
            }

            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_PrintDocument(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::UI::Xaml::Printing::PrintDocument>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_PrintDocument(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::UI::Xaml::Printing::PrintDocument>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_PrintDocument[] = {
        { "add_page", reinterpret_cast<PyCFunction>(PrintDocument_AddPage), METH_VARARGS, nullptr },
        { "add_pages_complete", reinterpret_cast<PyCFunction>(PrintDocument_AddPagesComplete), METH_VARARGS, nullptr },
        { "invalidate_preview", reinterpret_cast<PyCFunction>(PrintDocument_InvalidatePreview), METH_VARARGS, nullptr },
        { "set_preview_page", reinterpret_cast<PyCFunction>(PrintDocument_SetPreviewPage), METH_VARARGS, nullptr },
        { "set_preview_page_count", reinterpret_cast<PyCFunction>(PrintDocument_SetPreviewPageCount), METH_VARARGS, nullptr },
        { "add_add_pages", reinterpret_cast<PyCFunction>(PrintDocument_add_AddPages), METH_O, nullptr },
        { "remove_add_pages", reinterpret_cast<PyCFunction>(PrintDocument_remove_AddPages), METH_O, nullptr },
        { "add_get_preview_page", reinterpret_cast<PyCFunction>(PrintDocument_add_GetPreviewPage), METH_O, nullptr },
        { "remove_get_preview_page", reinterpret_cast<PyCFunction>(PrintDocument_remove_GetPreviewPage), METH_O, nullptr },
        { "add_paginate", reinterpret_cast<PyCFunction>(PrintDocument_add_Paginate), METH_O, nullptr },
        { "remove_paginate", reinterpret_cast<PyCFunction>(PrintDocument_remove_Paginate), METH_O, nullptr },
        { "_assign_array_", _assign_array_PrintDocument, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_PrintDocument), METH_O | METH_STATIC, nullptr },
        { }};

    static PyGetSetDef _getset_PrintDocument[] = {
        { "document_source", reinterpret_cast<getter>(PrintDocument_get_DocumentSource), nullptr, nullptr, nullptr },
        { }};

    static PyType_Slot _type_slots_PrintDocument[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_PrintDocument) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_PrintDocument) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_PrintDocument) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_PrintDocument) },
        { }};

    static PyType_Spec type_spec_PrintDocument = {
        "winrt._winrt_windows_ui_xaml_printing.PrintDocument",
        sizeof(py::winrt_wrapper<winrt::Windows::Foundation::IInspectable>),
        0,
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        _type_slots_PrintDocument};

    static PyGetSetDef getset_PrintDocument_Static[] = {
        { "document_source_property", reinterpret_cast<getter>(PrintDocument_get_DocumentSourceProperty), nullptr, nullptr, nullptr },
        { }};

    static PyMethodDef methods_PrintDocument_Static[] = {
        { }};

    static PyType_Slot type_slots_PrintDocument_Static[] = 
    {
        { Py_tp_base, reinterpret_cast<void*>(&PyType_Type) },
        { Py_tp_getset, reinterpret_cast<void*>(getset_PrintDocument_Static) },
        { Py_tp_methods, reinterpret_cast<void*>(methods_PrintDocument_Static) },
        { }
    };

    static PyType_Spec type_spec_PrintDocument_Static = {
        "winrt._winrt_windows_ui_xaml_printing.PrintDocument_Static",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
        type_slots_PrintDocument_Static};

    // ----- Windows.UI.Xaml.Printing Initialization --------------------

    PyDoc_STRVAR(module_doc, "Windows.UI.Xaml.Printing");

    static PyModuleDef module_def = {
        PyModuleDef_HEAD_INIT,
        "_winrt_windows_ui_xaml_printing",
        module_doc,
        0,
        nullptr,
        nullptr,
        nullptr,
        nullptr,
        nullptr};
} // py::cpp::Windows::UI::Xaml::Printing

PyMODINIT_FUNC PyInit__winrt_windows_ui_xaml_printing(void) noexcept
{
    using namespace py::cpp::Windows::UI::Xaml::Printing;

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

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

    if (!module)
    {
        return nullptr;
    }

    auto inspectable_meta_type = py::get_inspectable_meta_type();
    if (!inspectable_meta_type)
    {
        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;
    }

    py::pyobj_handle windows_ui_xaml_module{PyImport_ImportModule("winrt._winrt_windows_ui_xaml")};
    if (!windows_ui_xaml_module)
    {
        return nullptr;
    }

    py::pyobj_handle windows_ui_xaml_DependencyObject_type{PyObject_GetAttrString(windows_ui_xaml_module.get(), "DependencyObject")};
    if (!windows_ui_xaml_DependencyObject_type)
    {
        return nullptr;
    }

    py::pytype_handle AddPagesEventArgs_type{py::register_python_type(module.get(), &type_spec_AddPagesEventArgs, object_bases.get(), inspectable_meta_type)};
    if (!AddPagesEventArgs_type)
    {
        return nullptr;
    }

    py::pytype_handle GetPreviewPageEventArgs_type{py::register_python_type(module.get(), &type_spec_GetPreviewPageEventArgs, object_bases.get(), inspectable_meta_type)};
    if (!GetPreviewPageEventArgs_type)
    {
        return nullptr;
    }

    py::pytype_handle PaginateEventArgs_type{py::register_python_type(module.get(), &type_spec_PaginateEventArgs, object_bases.get(), inspectable_meta_type)};
    if (!PaginateEventArgs_type)
    {
        return nullptr;
    }

    py::pyobj_handle PrintDocument_Static_bases{PyTuple_Pack(1, reinterpret_cast<PyObject*>(Py_TYPE(windows_ui_xaml_DependencyObject_type.get())))};
    if (!PrintDocument_Static_bases)
    {
        return nullptr;
    }

    py::pyobj_handle type_PrintDocument_Static{PyType_FromSpecWithBases(&type_spec_PrintDocument_Static, PrintDocument_Static_bases.get())};
    if (!type_PrintDocument_Static)
    {
        return nullptr;
    }

    py::pyobj_handle PrintDocument_bases{PyTuple_Pack(1, windows_ui_xaml_DependencyObject_type.get())};
    if (!PrintDocument_bases)
    {
        return nullptr;
    }

    py::pytype_handle PrintDocument_type{py::register_python_type(module.get(), &type_spec_PrintDocument, PrintDocument_bases.get(), reinterpret_cast<PyTypeObject*>(type_PrintDocument_Static.get()))};
    if (!PrintDocument_type)
    {
        return nullptr;
    }


    return module.detach();
}
