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

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


namespace py::cpp::Windows::Phone::Devices::Power
{
    struct module_state
    {
        PyTypeObject* type_Battery;
    };

    // ----- Battery class --------------------
    static constexpr const char* const type_name_Battery = "Battery";

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

    static void _dealloc_Battery(py::wrapper::Windows::Phone::Devices::Power::Battery* 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* Battery_GetDefault(PyObject* /*unused*/, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_Size(args);

        if (arg_count == 0)
        {
            if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsMethodPresent(L"Windows.Phone.Devices.Power.Battery", L"GetDefault", 0))
            {
                py::set_arg_count_version_error(0);
                return nullptr;
            }

            try
            {
                return py::convert(winrt::Windows::Phone::Devices::Power::Battery::GetDefault());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* Battery_get_RemainingChargePercent(py::wrapper::Windows::Phone::Devices::Power::Battery* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Phone.Devices.Power.Battery", L"RemainingChargePercent"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.RemainingChargePercent());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* Battery_get_RemainingDischargeTime(py::wrapper::Windows::Phone::Devices::Power::Battery* self, void* /*unused*/) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsPropertyPresent(L"Windows.Phone.Devices.Power.Battery", L"RemainingDischargeTime"))
        {
            PyErr_SetString(PyExc_AttributeError, "property is not available in this version of Windows");
            return nullptr;
        }

        try
        {
            return py::convert(self->obj.RemainingDischargeTime());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* Battery_add_RemainingChargePercentChanged(py::wrapper::Windows::Phone::Devices::Power::Battery* self, PyObject* arg) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Phone.Devices.Power.Battery", L"RemainingChargePercentChanged"))
        {
            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(self->obj.RemainingChargePercentChanged(param0));
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* Battery_remove_RemainingChargePercentChanged(py::wrapper::Windows::Phone::Devices::Power::Battery* self, PyObject* arg) noexcept
    {
        if (!winrt::Windows::Foundation::Metadata::ApiInformation::IsEventPresent(L"Windows.Phone.Devices.Power.Battery", L"RemainingChargePercentChanged"))
        {
            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);

            self->obj.RemainingChargePercentChanged(param0);
            Py_RETURN_NONE;
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _assign_array_Battery(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Phone::Devices::Power::Battery>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_Battery(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::Phone::Devices::Power::Battery>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_Battery[] = {
        { "get_default", reinterpret_cast<PyCFunction>(Battery_GetDefault), METH_VARARGS | METH_STATIC, nullptr },
        { "add_remaining_charge_percent_changed", reinterpret_cast<PyCFunction>(Battery_add_RemainingChargePercentChanged), METH_O, nullptr },
        { "remove_remaining_charge_percent_changed", reinterpret_cast<PyCFunction>(Battery_remove_RemainingChargePercentChanged), METH_O, nullptr },
        { "_assign_array_", _assign_array_Battery, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_Battery), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_Battery[] = {
        { "remaining_charge_percent", reinterpret_cast<getter>(Battery_get_RemainingChargePercent), nullptr, nullptr, nullptr },
        { "remaining_discharge_time", reinterpret_cast<getter>(Battery_get_RemainingDischargeTime), nullptr, nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_Battery[] = 
    {
        { Py_tp_new, reinterpret_cast<void*>(_new_Battery) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_Battery) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_Battery) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_Battery) },
        { },
    };

    static PyType_Spec type_spec_Battery =
    {
        "_winsdk_Windows_Phone_Devices_Power.Battery",
        sizeof(py::wrapper::Windows::Phone::Devices::Power::Battery),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_Battery
    };

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

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

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

        return 0;
    }


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

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

PyMODINIT_FUNC PyInit__winsdk_Windows_Phone_Devices_Power(void) noexcept
{
    using namespace py::cpp::Windows::Phone::Devices::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);

    state->type_Battery = py::register_python_type(module.get(), type_name_Battery, &type_spec_Battery, bases.get(), nullptr);
    if (!state->type_Battery)
    {
        return nullptr;
    }


    return module.detach();
}

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

    PyObject* module = PyState_FindModule(&module_def);

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

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

    auto python_type = state->type_Battery;

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

    return python_type;
}
