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

#include "py.Windows.Globalization.Collation.h"

namespace py::cpp::Windows::Globalization::Collation
{
    // ----- CharacterGrouping class --------------------

    static PyObject* _new_CharacterGrouping(PyTypeObject* /*unused*/, PyObject* /*unused*/, PyObject* /*unused*/) noexcept
    {
        static_assert(py::py_type<winrt::Windows::Globalization::Collation::CharacterGrouping>::type_name);
        py::set_invalid_activation_error(py::py_type<winrt::Windows::Globalization::Collation::CharacterGrouping>::type_name);
        return nullptr;
    }

    static void _dealloc_CharacterGrouping(py::wrapper::Windows::Globalization::Collation::CharacterGrouping* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* CharacterGrouping_get_First(py::wrapper::Windows::Globalization::Collation::CharacterGrouping* 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.Globalization.Collation.CharacterGrouping", L"First");
            }

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

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

    static PyObject* CharacterGrouping_get_Label(py::wrapper::Windows::Globalization::Collation::CharacterGrouping* 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.Globalization.Collation.CharacterGrouping", L"Label");
            }

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

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

    static PyObject* _assign_array_CharacterGrouping(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Globalization::Collation::CharacterGrouping>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_CharacterGrouping(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::Globalization::Collation::CharacterGrouping>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyMethodDef _methods_CharacterGrouping[] = {
        { "_assign_array_", _assign_array_CharacterGrouping, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_CharacterGrouping), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_CharacterGrouping[] = {
        { "first", reinterpret_cast<getter>(CharacterGrouping_get_First), nullptr, nullptr, nullptr },
        { "label", reinterpret_cast<getter>(CharacterGrouping_get_Label), nullptr, nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_CharacterGrouping[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_CharacterGrouping) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_CharacterGrouping) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_CharacterGrouping) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_CharacterGrouping) },
        { }
    };

    static PyType_Spec type_spec_CharacterGrouping = {
        "winrt._winrt_windows_globalization_collation.CharacterGrouping",
        sizeof(py::wrapper::Windows::Globalization::Collation::CharacterGrouping),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_CharacterGrouping};

    // ----- CharacterGroupings class --------------------

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

        auto arg_count = PyTuple_Size(args);
        if (arg_count == 1)
        {
            try
            {
                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                winrt::Windows::Globalization::Collation::CharacterGroupings instance{param0};
                return py::wrap(instance, type);
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else if (arg_count == 0)
        {
            try
            {
                winrt::Windows::Globalization::Collation::CharacterGroupings 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_CharacterGroupings(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self) noexcept
    {
        auto tp = Py_TYPE(self);
        std::destroy_at(&self->obj);
        tp->tp_free(self);
        Py_DECREF(tp);
    }

    static PyObject* CharacterGroupings_First(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_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.Globalization.Collation.CharacterGroupings", L"First", 0);
                }

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

                return py::convert(self->obj.First());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* CharacterGroupings_GetAt(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_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.Globalization.Collation.CharacterGroupings", L"GetAt", 1);
                }

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

                auto param0 = py::convert_to<uint32_t>(args, 0);

                return py::convert(self->obj.GetAt(param0));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* CharacterGroupings_GetMany(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_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.Globalization.Collation.CharacterGroupings", L"GetMany", 1);
                }

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

                auto param0 = py::convert_to<uint32_t>(args, 0);
                auto param1 = py::convert_to<py::pybuf_view<winrt::Windows::Globalization::Collation::CharacterGrouping, true>>(args, 1);

                return py::convert(self->obj.GetMany(param0, param1));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* CharacterGroupings_IndexOf(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_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.Globalization.Collation.CharacterGroupings", L"IndexOf", 1);
                }

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

                auto param0 = py::convert_to<winrt::Windows::Globalization::Collation::CharacterGrouping>(args, 0);
                uint32_t param1{};

                auto return_value = self->obj.IndexOf(param0, param1);

                py::pyobj_handle out_return_value{ py::convert(return_value) };
                if (!out_return_value)
                {
                    return nullptr;
                }
                py::pyobj_handle out1{ py::convert(param1) };
                if (!out1)
                {
                    return nullptr;
                }
                return PyTuple_Pack(2, out_return_value.get(), out1.get());
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* CharacterGroupings_Lookup(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* args) noexcept
    {
        auto arg_count = PyTuple_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.Globalization.Collation.CharacterGroupings", L"Lookup", 1);
                }

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

                auto param0 = py::convert_to<winrt::hstring>(args, 0);

                return py::convert(self->obj.Lookup(param0));
            }
            catch (...)
            {
                py::to_PyErr();
                return nullptr;
            }
        }
        else
        {
            py::set_invalid_arg_count_error(arg_count);
            return nullptr;
        }
    }

    static PyObject* CharacterGroupings_get_Size(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* 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.Globalization.Collation.CharacterGroupings", L"Size");
            }

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

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

    static PyObject* _assign_array_CharacterGroupings(PyObject* /*unused*/, PyObject* arg) noexcept
    {
        auto array = std::make_unique<py::ComArray<winrt::Windows::Globalization::Collation::CharacterGroupings>>();
        if (!py::cpp::_winrt::Array_Assign(arg, std::move(array)))
        {
            return nullptr;
        }
        Py_RETURN_NONE;
    }

    static PyObject* _from_CharacterGroupings(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::Globalization::Collation::CharacterGroupings>());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _iterator_CharacterGroupings(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self) noexcept
    {
        try
        {
            return py::convert(self->obj.First());
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static Py_ssize_t _seq_length_CharacterGroupings(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self) noexcept
    {
        try
        {
            return static_cast<Py_ssize_t>(self->obj.Size());
        }
        catch (...)
        {
            py::to_PyErr();
            return -1;
        }
    }

    static PyObject* _seq_item_CharacterGroupings(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, Py_ssize_t i) noexcept
    {
        try
        {
            return py::convert(self->obj.GetAt(static_cast<uint32_t>(i)));
        }
        catch (...)
        {
            py::to_PyErr();
            return nullptr;
        }
    }

    static PyObject* _seq_subscript_CharacterGroupings(py::wrapper::Windows::Globalization::Collation::CharacterGroupings* self, PyObject* slice) noexcept
    {
        try
        {
            if (PyIndex_Check(slice))
            {
                pyobj_handle index{PyNumber_Index(slice)};

                if (!index)
                {
                    return nullptr;
                }

                auto i = PyNumber_AsSsize_t(index.get(), PyExc_IndexError);

                if (i == -1 && PyErr_Occurred())
                {
                    return nullptr;
                }

                return _seq_item_CharacterGroupings(self, i);
            }

            if (!PySlice_Check(slice))
            {
                PyErr_Format(PyExc_TypeError, "indices must be integers, not '%s'", Py_TYPE(slice)->tp_name);
            }

            Py_ssize_t start, stop, step, length;

            if (PySlice_GetIndicesEx(slice, self->obj.Size(), &start, &stop, &step, &length) < 0)
            {
                return nullptr;
            }

            if (step != 1)
            {
                PyErr_SetString(PyExc_NotImplementedError, "slices with step other than 1 are not implemented");
                return nullptr;
            }

            winrt::com_array<winrt::Windows::Globalization::Collation::CharacterGrouping> items(static_cast<uint32_t>(length), empty_instance<winrt::Windows::Globalization::Collation::CharacterGrouping>::get());

            auto count = self->obj.GetMany(static_cast<uint32_t>(start), items);

            if (count != static_cast<uint32_t>(length))
            {
                PyErr_Format(PyExc_RuntimeError, "returned count %d did not match requested length %zd", count, length);
                return nullptr;
            }

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

    static PyMethodDef _methods_CharacterGroupings[] = {
        { "first", reinterpret_cast<PyCFunction>(CharacterGroupings_First), METH_VARARGS, nullptr },
        { "get_at", reinterpret_cast<PyCFunction>(CharacterGroupings_GetAt), METH_VARARGS, nullptr },
        { "get_many", reinterpret_cast<PyCFunction>(CharacterGroupings_GetMany), METH_VARARGS, nullptr },
        { "index_of", reinterpret_cast<PyCFunction>(CharacterGroupings_IndexOf), METH_VARARGS, nullptr },
        { "lookup", reinterpret_cast<PyCFunction>(CharacterGroupings_Lookup), METH_VARARGS, nullptr },
        { "_assign_array_", _assign_array_CharacterGroupings, METH_O | METH_STATIC, nullptr },
        { "_from", reinterpret_cast<PyCFunction>(_from_CharacterGroupings), METH_O | METH_STATIC, nullptr },
        { }
    };

    static PyGetSetDef _getset_CharacterGroupings[] = {
        { "size", reinterpret_cast<getter>(CharacterGroupings_get_Size), nullptr, nullptr, nullptr },
        { }
    };

    static PyType_Slot _type_slots_CharacterGroupings[] = {
        { Py_tp_new, reinterpret_cast<void*>(_new_CharacterGroupings) },
        { Py_tp_dealloc, reinterpret_cast<void*>(_dealloc_CharacterGroupings) },
        { Py_tp_methods, reinterpret_cast<void*>(_methods_CharacterGroupings) },
        { Py_tp_getset, reinterpret_cast<void*>(_getset_CharacterGroupings) },
        { Py_tp_iter, reinterpret_cast<void*>(_iterator_CharacterGroupings) },
        { Py_sq_length, reinterpret_cast<void*>(_seq_length_CharacterGroupings) },
        { Py_sq_item, reinterpret_cast<void*>(_seq_item_CharacterGroupings) },
        { Py_mp_subscript, reinterpret_cast<void*>(_seq_subscript_CharacterGroupings) },
        { }
    };

    static PyType_Spec type_spec_CharacterGroupings = {
        "winrt._winrt_windows_globalization_collation.CharacterGroupings",
        sizeof(py::wrapper::Windows::Globalization::Collation::CharacterGroupings),
        0,
        Py_TPFLAGS_DEFAULT,
        _type_slots_CharacterGroupings};

    // ----- Windows.Globalization.Collation Initialization --------------------

    PyDoc_STRVAR(module_doc, "Windows.Globalization.Collation");

    static PyModuleDef module_def = {
        PyModuleDef_HEAD_INIT,
        "_winrt_windows_globalization_collation",
        module_doc,
        0,
        nullptr,
        nullptr,
        nullptr,
        nullptr,
        nullptr};
} // py::cpp::Windows::Globalization::Collation

PyMODINIT_FUNC PyInit__winrt_windows_globalization_collation(void) noexcept
{
    using namespace py::cpp::Windows::Globalization::Collation;

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

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

    if (!module)
    {
        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::pytype_handle CharacterGrouping_type{py::register_python_type(module.get(), &type_spec_CharacterGrouping, object_bases.get(), nullptr)};
    if (!CharacterGrouping_type)
    {
        return nullptr;
    }

    py::pytype_handle CharacterGroupings_type{py::register_python_type(module.get(), &type_spec_CharacterGroupings, object_bases.get(), nullptr)};
    if (!CharacterGroupings_type)
    {
        return nullptr;
    }


    return module.detach();
}
