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

#include "py.Windows.Phone.System.Power.h"

namespace py::cpp::Windows::Phone::System::Power
{
    // ----- PowerManager class --------------------

    static PyObject* _new_PowerManager(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Phone::System::Power::PowerManager>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Phone::System::Power::PowerManager>::type_name);
        return nullptr;
    }

    static PyObject* PowerManager_get_PowerSavingMode(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.Phone.System.Power.PowerManager", L"PowerSavingMode");
            }

            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::Phone::System::Power::PowerManager::PowerSavingMode();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_get_PowerSavingModeEnabled(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.Phone.System.Power.PowerManager", L"PowerSavingModeEnabled");
            }

            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::Phone::System::Power::PowerManager::PowerSavingModeEnabled();
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_add_PowerSavingModeChanged(PyObject* /*unused*/, 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.Phone.System.Power.PowerManager", L"PowerSavingModeChanged");
            }

            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::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>>(arg);

            return py::convert([&]()
            {
                auto _gil = release_gil();
                return winrt::Windows::Phone::System::Power::PowerManager::PowerSavingModeChanged(param0);
            }());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_remove_PowerSavingModeChanged(PyObject* /*unused*/, 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.Phone.System.Power.PowerManager", L"PowerSavingModeChanged");
            }

            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();
                winrt::Windows::Phone::System::Power::PowerManager::PowerSavingModeChanged(param0);
            }

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

    static PyMethodDef _methods_PowerManager[] = {
        { }};

    static PyGetSetDef _getset_PowerManager[] = {
        { }};

    static PyType_Slot _type_slots_PowerManager[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_PowerManager) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_PowerManager) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_PowerManager) },
        { }};

    static PyType_Spec type_spec_PowerManager = {
        "winrt._winrt_windows_phone_system_power.PowerManager",
        0,
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_PowerManager};

    static PyGetSetDef getset_PowerManager_Static[] = {
        { "power_saving_mode", reinterpret_cast<getter>(PowerManager_get_PowerSavingMode), nullptr, nullptr, nullptr },
        { "power_saving_mode_enabled", reinterpret_cast<getter>(PowerManager_get_PowerSavingModeEnabled), nullptr, nullptr, nullptr },
        { }};

    static PyMethodDef methods_PowerManager_Static[] = {
        { "add_power_saving_mode_changed", reinterpret_cast<PyCFunction>(PowerManager_add_PowerSavingModeChanged), METH_O, nullptr },
        { "remove_power_saving_mode_changed", reinterpret_cast<PyCFunction>(PowerManager_remove_PowerSavingModeChanged), METH_O, nullptr },
        { }};

    static PyType_Slot type_slots_PowerManager_Static[] = 
    {
        { Py_tp_base, reinterpret_cast<void*>(&PyType_Type) },
        { Py_tp_getset, reinterpret_cast<void*>(getset_PowerManager_Static) },
        { Py_tp_methods, reinterpret_cast<void*>(methods_PowerManager_Static) },
        { }
    };

    static PyType_Spec type_spec_PowerManager_Static = {
        "winrt._winrt_windows_phone_system_power.PowerManager_Static",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT,
        type_slots_PowerManager_Static};

    // ----- Windows.Phone.System.Power Initialization --------------------

    PyDoc_STRVAR(module_doc, "Windows.Phone.System.Power");

    static PyModuleDef module_def = {
        PyModuleDef_HEAD_INIT,
        "_winrt_windows_phone_system_power",
        module_doc,
        0,
        nullptr,
        nullptr,
        nullptr,
        nullptr,
        nullptr};
} // py::cpp::Windows::Phone::System::Power

PyMODINIT_FUNC PyInit__winrt_windows_phone_system_power(void) noexcept
{
    using namespace py::cpp::Windows::Phone::System::Power;

    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 PowerManager_Static_bases{PyTuple_Pack(1, reinterpret_cast<PyObject*>(inspectable_meta_type))};
    if (!PowerManager_Static_bases)
    {
        return nullptr;
    }

    py::pyobj_handle type_PowerManager_Static{PyType_FromSpecWithBases(&type_spec_PowerManager_Static, PowerManager_Static_bases.get())};
    if (!type_PowerManager_Static)
    {
        return nullptr;
    }

    py::pytype_handle PowerManager_type{py::register_python_type(module.get(), &type_spec_PowerManager, object_bases.get(), reinterpret_cast<PyTypeObject*>(type_PowerManager_Static.get()))};
    if (!PowerManager_type)
    {
        return nullptr;
    }


    return module.detach();
}
