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

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


namespace py::cpp::Windows::Phone::System::Power
{
    struct module_state
    {
        PyObject* type_PowerSavingMode;
        PyTypeObject* type_PowerManager;
    };

    static PyObject* register_PowerSavingMode(PyObject* module, PyObject* type) noexcept
    {
        auto state = reinterpret_cast<module_state*>(PyModule_GetState(module));
        assert(state);

        if (state->type_PowerSavingMode)
        {
            PyErr_SetString(PyExc_RuntimeError, "type has already been registered");
            return nullptr;
        }

        if (!PyType_Check(type))
        {
            PyErr_SetString(PyExc_TypeError, "argument is not a type");
            return nullptr;
        }

        state->type_PowerSavingMode = type;
        Py_INCREF(state->type_PowerSavingMode);


        Py_RETURN_NONE;
    }

    // ----- PowerManager class --------------------
    constexpr const char* const type_name_PowerManager = "PowerManager";

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

    static PyObject* PowerManager_get_PowerSavingMode(PyObject* /*unused*/, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Phone.System.Power.PowerManager", L"PowerSavingMode"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(winrt::Windows::Phone::System::Power::PowerManager::PowerSavingMode());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_get_PowerSavingModeEnabled(PyObject* /*unused*/, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Phone.System.Power.PowerManager", L"PowerSavingModeEnabled"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(winrt::Windows::Phone::System::Power::PowerManager::PowerSavingModeEnabled());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_add_PowerSavingModeChanged(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Phone.System.Power.PowerManager", L"PowerSavingModeChanged"))
        {
            PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            auto param0 = py::convert_to<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>>(arg);

            return py::convert(winrt::Windows::Phone::System::Power::PowerManager::PowerSavingModeChanged(param0));
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* PowerManager_remove_PowerSavingModeChanged(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Phone.System.Power.PowerManager", L"PowerSavingModeChanged"))
        {
            PyErr_SetString(PyExc_AttributeError, "event is not available in this version of Windows");
            return nullptr;
        }

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

            winrt::Windows::Phone::System::Power::PowerManager::PowerSavingModeChanged(param0);
            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

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

    static PyGetSetDef _getset_PowerManager[] = {
        { }
    };

    static PyType_Slot _type_slots_PowerManager[] = 
    {
        { Py_tp_new, _new_PowerManager },
        { Py_tp_methods, _methods_PowerManager },
        { Py_tp_getset, _getset_PowerManager },
        { },
    };

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

    static PyGetSetDef getset_PowerManager_Meta[] = {
        { "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 PyType_Slot type_slots_PowerManager_Meta[] = 
    {
        { Py_tp_base, &PyType_Type },
        { Py_tp_getset, getset_PowerManager_Meta },
        { }
    };

    static PyType_Spec type_spec_PowerManager_Meta =
    {
        "_winsdk_Windows_Phone_System_Power.PowerManager_Meta",
        static_cast<int>(PyType_Type.tp_basicsize),
        static_cast<int>(PyType_Type.tp_itemsize),
        Py_TPFLAGS_DEFAULT,
        type_slots_PowerManager_Meta
    };

    // ----- Windows.Phone.System.Power Initialization --------------------
    PyDoc_STRVAR(module_doc, "Windows::Phone::System::Power");

    static PyMethodDef module_methods[] = {
        {"_register_PowerSavingMode", register_PowerSavingMode, METH_O, "registers type"},
        {}};


    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_PowerSavingMode);
        Py_VISIT(state->type_PowerManager);

        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_PowerSavingMode);
        Py_CLEAR(state->type_PowerManager);

        return 0;
    }


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

} // py::cpp::Windows::Phone::System::Power

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

    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);

    py::pyobj_handle type_PowerManager_Meta{PyType_FromSpec(&type_spec_PowerManager_Meta)};
    if (!type_PowerManager_Meta)
    {
        return nullptr;
    }

    state->type_PowerManager = py::register_python_type(module.get(), type_name_PowerManager, &type_spec_PowerManager, nullptr, reinterpret_cast<PyTypeObject*>(type_PowerManager_Meta.get()));
    if (!state->type_PowerManager)
    {
        return nullptr;
    }


    return module.detach();
}

PyObject* py::py_type<winrt::Windows::Phone::System::Power::PowerSavingMode>::get_python_type() noexcept {
    using namespace py::cpp::Windows::Phone::System::Power;

    PyObject* module = PyState_FindModule(&module_def);

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

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

    auto python_type = state->type_PowerSavingMode;

    if (!python_type) {
        PyErr_SetString(PyExc_RuntimeError, "type winrt::Windows::Phone::System::Power::PowerSavingMode is not registered");
        return nullptr;
    }

    return python_type;
}

PyTypeObject* py::winrt_type<winrt::Windows::Phone::System::Power::PowerManager>::get_python_type() noexcept {
    using namespace py::cpp::Windows::Phone::System::Power;

    PyObject* module = PyState_FindModule(&module_def);

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

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

    auto python_type = state->type_PowerManager;

    if (!python_type) {
        PyErr_SetString(PyExc_RuntimeError, "type winrt::Windows::Phone::System::Power::PowerManager is not registered");
        return nullptr;
    }

    return python_type;
}
