/*
 * Interface wrapper code.
 *
 * Generated by SIP 6.15.3
 *
 * Copyright (c) 2026 Riverbank Computing Limited <info@riverbankcomputing.com>
 * 
 * This file is part of PyQt6-WebEngine.
 * 
 * This file may be used under the terms of the GNU General Public License
 * version 3.0 as published by the Free Software Foundation and appearing in
 * the file LICENSE included in the packaging of this file.  Please review the
 * following information to ensure the GNU General Public License version 3.0
 * requirements will be met: http://www.gnu.org/copyleft/gpl.html.
 * 
 * If you do not wish to use this file under the terms of the GPL version 3.0
 * then you may purchase a commercial license.  For more information contact
 * info@riverbankcomputing.com.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "sipAPIQtWebEngineCore.h"

#line 259 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtCore/qpycore_qmap.sip"
#include <qmap.h>
#line 29 "/build/pyqt6-webengine/src/pyqt6_webengine-6.11.0/build/QtWebEngineCore/sipQtWebEngineCoreQMultiMap0100QByteArray0100QByteArray.cpp"

#line 30 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtCore/qbytearray.sip"
#include <qbytearray.h>
#line 33 "/build/pyqt6-webengine/src/pyqt6_webengine-6.11.0/build/QtWebEngineCore/sipQtWebEngineCoreQMultiMap0100QByteArray0100QByteArray.cpp"


extern "C" {static void assign_QMultiMap_0100QByteArray_0100QByteArray(void *, Py_ssize_t, void *);}
static void assign_QMultiMap_0100QByteArray_0100QByteArray(void *sipDst, Py_ssize_t sipDstIdx, void *sipSrc)
{
    reinterpret_cast<QMultiMap< ::QByteArray, ::QByteArray> *>(sipDst)[sipDstIdx] = *reinterpret_cast<QMultiMap< ::QByteArray, ::QByteArray> *>(sipSrc);
}


extern "C" {static void *array_QMultiMap_0100QByteArray_0100QByteArray(Py_ssize_t);}
static void *array_QMultiMap_0100QByteArray_0100QByteArray(Py_ssize_t sipNrElem)
{
    return new QMultiMap< ::QByteArray, ::QByteArray>[sipNrElem];
}


extern "C" {static void *copy_QMultiMap_0100QByteArray_0100QByteArray(const void *, Py_ssize_t);}
static void *copy_QMultiMap_0100QByteArray_0100QByteArray(const void *sipSrc, Py_ssize_t sipSrcIdx)
{
    return new QMultiMap< ::QByteArray, ::QByteArray>(reinterpret_cast<const QMultiMap< ::QByteArray, ::QByteArray> *>(sipSrc)[sipSrcIdx]);
}


/* Call the mapped type's destructor. */
extern "C" {static void release_QMultiMap_0100QByteArray_0100QByteArray(void *, int, void *);}
static void release_QMultiMap_0100QByteArray_0100QByteArray(void *sipCppV, int, void *)
{
    QMultiMap< ::QByteArray, ::QByteArray> *sipCpp = reinterpret_cast<QMultiMap< ::QByteArray, ::QByteArray> *>(sipCppV);
    delete sipCpp;
}



extern "C" {static int convertTo_QMultiMap_0100QByteArray_0100QByteArray(PyObject *, void **, int *, PyObject *, void **);}
static int convertTo_QMultiMap_0100QByteArray_0100QByteArray(PyObject *sipPy, void **sipCppPtrV, int *sipIsErr, PyObject *sipTransferObj, void **)
{
    QMultiMap< ::QByteArray, ::QByteArray> **sipCppPtr = reinterpret_cast<QMultiMap< ::QByteArray, ::QByteArray> **>(sipCppPtrV);

#line 341 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtCore/qpycore_qmap.sip"
    if (sipIsErr == NULL)
        return PyDict_Check(sipPy);

    QMultiMap<QByteArray, QByteArray> *qm = new QMultiMap<QByteArray, QByteArray>;

    Py_ssize_t i = 0;
    PyObject *kobj, *vobj;

    while (PyDict_Next(sipPy, &i, &kobj, &vobj))
    {
        int kstate;

        QByteArray *k = reinterpret_cast<QByteArray *>(sipConvertToType(kobj, sipType_QByteArray, sipTransferObj, SIP_NOT_NONE, &kstate, sipIsErr));

        if (*sipIsErr)
        {
            PyErr_Format(PyExc_TypeError,
                    "a dict key has type '%s' but 'QByteArray' is expected",
                    sipPyTypeName(Py_TYPE(kobj)));

            delete qm;

            return 0;
        }

        Py_ssize_t vi = PySequence_Size(vobj);

        if (vi < 0)
        {
            PyErr_Format(PyExc_TypeError,
                    "a dict value has type '%s' but a sequence is expected",
                    sipPyTypeName(Py_TYPE(vobj)));

            *sipIsErr = 1;
            sipReleaseType(k, sipType_QByteArray, kstate);
            delete qm;

            return 0;
        }

        // We go through the sequence backwards to maintain the Qt semantics of
        // later items appearing first.
        while (vi--)
        {
            PyObject *itm_obj = PySequence_GetItem(vobj, vi);

            if (!itm_obj)
            {
                *sipIsErr = 1;
                sipReleaseType(k, sipType_QByteArray, kstate);
                delete qm;

                return 0;
            }

            int itm_state;

            QByteArray *itm = reinterpret_cast<QByteArray *>(sipConvertToType(itm_obj, sipType_QByteArray, sipTransferObj, SIP_NOT_NONE, &itm_state, sipIsErr));

            Py_DECREF(itm_obj);

            if (*sipIsErr)
            {
                PyErr_Format(PyExc_TypeError,
                        "a sequence element has type '%s' but 'QByteArray' is expected",
                        sipPyTypeName(Py_TYPE(itm_obj)));

                sipReleaseType(k, sipType_QByteArray, kstate);
                delete qm;

                return 0;
            }

            qm->insert(*k, *itm);
            sipReleaseType(itm, sipType_QByteArray, itm_state);
        }

        sipReleaseType(k, sipType_QByteArray, kstate);
    }

    *sipCppPtr = qm;

    return sipGetState(sipTransferObj);
#line 156 "/build/pyqt6-webengine/src/pyqt6_webengine-6.11.0/build/QtWebEngineCore/sipQtWebEngineCoreQMultiMap0100QByteArray0100QByteArray.cpp"
}


extern "C" {static PyObject *convertFrom_QMultiMap_0100QByteArray_0100QByteArray(void *, PyObject *);}
static PyObject *convertFrom_QMultiMap_0100QByteArray_0100QByteArray(void *sipCppV, PyObject *sipTransferObj)
{
    QMultiMap< ::QByteArray, ::QByteArray> *sipCpp = reinterpret_cast<QMultiMap< ::QByteArray, ::QByteArray> *>(sipCppV);

#line 263 "/usr/lib/python3.14/site-packages/PyQt6/bindings/QtCore/qpycore_qmap.sip"
    PyObject *d = PyDict_New();

    if (!d)
        return 0;

    QList<QByteArray> keys = sipCpp->keys();
    QList<QByteArray>::const_iterator kit = keys.constBegin();
    QList<QByteArray>::const_iterator kit_end = keys.constEnd();

    while (kit != kit_end)
    {
        QByteArray *k = new QByteArray(*kit);
        PyObject *kobj = sipConvertFromNewType(k, sipType_QByteArray,
                sipTransferObj);

        if (!kobj)
        {
            delete k;
            Py_DECREF(d);

            return 0;
        }

        // Create a Python list as the dictionary value.
        QList<QByteArray> values = sipCpp->values(*kit);
        PyObject *vobj = PyList_New(values.count());

        if (!vobj)
        {
            Py_DECREF(kobj);
            Py_DECREF(d);

            return 0;
        }

        QList<QByteArray>::const_iterator vit = values.constBegin();
        QList<QByteArray>::const_iterator vit_end = values.constEnd();

        for (int i = 0; vit != vit_end; ++i)
        {
            QByteArray *sv = new QByteArray(*vit);
            PyObject *svobj = sipConvertFromNewType(sv, sipType_QByteArray,
                    sipTransferObj);

            if (!svobj)
            {
                delete sv;
                Py_DECREF(vobj);
                Py_DECREF(kobj);
                Py_DECREF(d);

                return 0;
            }

            PyList_SetItem(vobj, i, svobj);

            ++vit;
        }

        int rc = PyDict_SetItem(d, kobj, vobj);

        Py_DECREF(vobj);
        Py_DECREF(kobj);

        if (rc < 0)
        {
            Py_DECREF(d);

            return 0;
        }

        ++kit;
    }

    return d;
#line 241 "/build/pyqt6-webengine/src/pyqt6_webengine-6.11.0/build/QtWebEngineCore/sipQtWebEngineCoreQMultiMap0100QByteArray0100QByteArray.cpp"
}


sipMappedTypeDef sipTypeDef_QtWebEngineCore_QMultiMap_0100QByteArray_0100QByteArray = {
    {
        SIP_NULLPTR,
        SIP_TYPE_MAPPED,
        sipNameNr_2076,
        SIP_NULLPTR,
        SIP_NULLPTR,
    },
    {
        -1,
        {0, 0, 1},
        0, SIP_NULLPTR,
        0, SIP_NULLPTR,
        {SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR, SIP_NULLPTR}
    },
    assign_QMultiMap_0100QByteArray_0100QByteArray,
    array_QMultiMap_0100QByteArray_0100QByteArray,
    copy_QMultiMap_0100QByteArray_0100QByteArray,
    release_QMultiMap_0100QByteArray_0100QByteArray,
    convertTo_QMultiMap_0100QByteArray_0100QByteArray,
    convertFrom_QMultiMap_0100QByteArray_0100QByteArray
};
