/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt for Python.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//workaround to access protected functions
#define protected public

// default includes
#include <shiboken.h>
#ifndef QT_NO_VERSION_TAGGING
#  define QT_NO_VERSION_TAGGING
#endif
#include <QDebug>
#include <pysidesignal.h>
#include <pysideproperty.h>
#include <pyside.h>
#include <pysideqenum.h>
#include <feature_select.h>
QT_WARNING_DISABLE_DEPRECATED

#include <typeinfo>
#include <iterator>

// module include
#include "pyside6_qthelp_python.h"

// main header
#include "qhelplink_wrapper.h"

// inner classes

#include <cctype>
#include <cstring>



template <class T>
static const char *typeNameOf(const T &t)
{
    const char *typeName =  typeid(t).name();
    auto size = std::strlen(typeName);
#if defined(Q_CC_MSVC) // MSVC: "class QPaintDevice * __ptr64"
    if (auto lastStar = strchr(typeName, '*')) {
        // MSVC: "class QPaintDevice * __ptr64"
        while (*--lastStar == ' ') {
        }
        size = lastStar - typeName + 1;
    }
#else // g++, Clang: "QPaintDevice *" -> "P12QPaintDevice"
    if (size > 2 && typeName[0] == 'P' && std::isdigit(typeName[1])) {
        ++typeName;
        --size;
    }
#endif
    char *result = new char[size + 1];
    result[size] = '\0';
    memcpy(result, typeName, size);
    return result;
}


// Target ---------------------------------------------------------

extern "C" {
static int
Sbk_QHelpLink_Init(PyObject *self, PyObject *args, PyObject *kwds)
{
    SbkObject *sbkSelf = reinterpret_cast<SbkObject *>(self);
    PySide::Feature::Select(self);
    if (Shiboken::Object::isUserType(self) && !Shiboken::ObjectType::canCallConstructor(self->ob_type, Shiboken::SbkType< ::QHelpLink >()))
        return -1;

    ::QHelpLink *cptr{};
    Shiboken::AutoDecRef errInfo{};
    static const char *fullName = "PySide6.QtHelp.QHelpLink.__init__";
    SBK_UNUSED(fullName)
    int overloadId = -1;
    Shiboken::Conversions::PythonToCppConversion pythonToCpp[1];
    SBK_UNUSED(pythonToCpp)
    const Py_ssize_t numArgs = PyTuple_GET_SIZE(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {0};

    // invalid argument lengths


    if (!PyArg_UnpackTuple(args, "QHelpLink", 0, 1, &(pyArgs[0])))
        return -1;


    // Overloaded function decisor
    // 0: QHelpLink::QHelpLink()
    // 1: QHelpLink::QHelpLink(QHelpLink)
    if (numArgs == 0) {
        overloadId = 0; // QHelpLink()
    } else if (numArgs == 1
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppReferenceConversion(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], (pyArgs[0])))) {
        overloadId = 1; // QHelpLink(QHelpLink)
    }

    // Function signature not found.
    if (overloadId == -1) goto Sbk_QHelpLink_Init_TypeError;

    // Call function/method
    switch (overloadId) {
        case 0: // QHelpLink()
        {

            if (!PyErr_Occurred()) {
                // QHelpLink()
                cptr = new ::QHelpLink();
            }
            break;
        }
        case 1: // QHelpLink(const QHelpLink & QHelpLink)
        {
            if (!Shiboken::Object::isValid(pyArgs[0]))
                return -1;
            ::QHelpLink cppArg0_local;
            ::QHelpLink *cppArg0 = &cppArg0_local;
            if (pythonToCpp[0].isValue())
                pythonToCpp[0](pyArgs[0], &cppArg0_local);
            else
                pythonToCpp[0](pyArgs[0], &cppArg0);


            if (!PyErr_Occurred()) {
                // QHelpLink(QHelpLink)
                cptr = new ::QHelpLink(*cppArg0);
            }
            break;
        }
    }

    if (PyErr_Occurred() || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< ::QHelpLink >(), cptr)) {
        delete cptr;
        return -1;
    }
    if (!cptr) goto Sbk_QHelpLink_Init_TypeError;

    Shiboken::Object::setValidCpp(sbkSelf, true);
    if (Shiboken::BindingManager::instance().hasWrapper(cptr)) {
        Shiboken::BindingManager::instance().releaseWrapper(Shiboken::BindingManager::instance().retrieveWrapper(cptr));
    }
    Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);


    return 1;

    Sbk_QHelpLink_Init_TypeError:
        Shiboken::setErrorAboutWrongArguments(args, fullName, errInfo);
        return -1;
}

static PyObject *Sbk_QHelpLink___copy__(PyObject *self)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    auto &cppSelf = *reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(self)));
    PyObject *pyResult = Shiboken::Conversions::copyToPython(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], &cppSelf);
    if (PyErr_Occurred() || !pyResult) {
        Py_XDECREF(pyResult);
        return {};
    }
    return pyResult;
}


static const char *Sbk_QHelpLink_PropertyStrings[] = {
    nullptr // Sentinel
};

static PyMethodDef Sbk_QHelpLink_methods[] = {

    {"__copy__", reinterpret_cast<PyCFunction>(Sbk_QHelpLink___copy__), METH_NOARGS},
    {nullptr, nullptr} // Sentinel
};

static PyObject *Sbk_QHelpLink_get_url(PyObject *self, void *)
{
    if (!Shiboken::Object::isValid(self))
        return nullptr;
    auto cppSelf = reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyOut = {};
    if (reinterpret_cast<void *>(&(cppSelf->url)) == reinterpret_cast<void *>(cppSelf)) {
        pyOut = reinterpret_cast<PyObject *>(Shiboken::Object::findColocatedChild(reinterpret_cast<SbkObject *>(self), SbkPySide6_QtCoreTypes[SBK_QURL_IDX]));
        if (pyOut) {
            Py_IncRef(pyOut);
            return pyOut;
        }
    } else if (Shiboken::BindingManager::instance().hasWrapper(&(cppSelf->url))) {
        pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(&(cppSelf->url)));
        Py_IncRef(pyOut);
        return pyOut;
    }
    pyOut = Shiboken::Object::newObject(SbkPySide6_QtCoreTypes[SBK_QURL_IDX], &(cppSelf->url), false, true);
    Shiboken::Object::setParent(self, pyOut);
    return pyOut;
}
static int Sbk_QHelpLink_set_url(PyObject *self, PyObject *pyIn, void *)
{
    if (!Shiboken::Object::isValid(self))
        return 0;
    auto cppSelf = reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    if (pyIn == nullptr) {
        PyErr_SetString(PyExc_TypeError, "'url' may not be deleted");
        return -1;
    }
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    if (!(pythonToCpp = Shiboken::Conversions::pythonToCppValueConversion(SbkPySide6_QtCoreTypes[SBK_QURL_IDX], (pyIn)))) {
        PyErr_SetString(PyExc_TypeError, "wrong type attributed to 'url', 'QUrl' or convertible type expected");
        return -1;
    }

    auto &cppOut_ptr = cppSelf->url;
    pythonToCpp(pyIn, &cppOut_ptr);

    return 0;
}

static PyObject *Sbk_QHelpLink_get_title(PyObject *self, void *)
{
    if (!Shiboken::Object::isValid(self))
        return nullptr;
    auto cppSelf = reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    PyObject *pyOut = {};
    pyOut = Shiboken::Conversions::copyToPython(SbkPySide6_QtCoreTypeConverters[SBK_QSTRING_IDX], &cppSelf->title);
    return pyOut;
}
static int Sbk_QHelpLink_set_title(PyObject *self, PyObject *pyIn, void *)
{
    if (!Shiboken::Object::isValid(self))
        return 0;
    auto cppSelf = reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(self)));
    SBK_UNUSED(cppSelf)
    if (pyIn == nullptr) {
        PyErr_SetString(PyExc_TypeError, "'title' may not be deleted");
        return -1;
    }
    Shiboken::Conversions::PythonToCppConversion pythonToCpp;
    if (!(pythonToCpp = Shiboken::Conversions::pythonToCppConversion(SbkPySide6_QtCoreTypeConverters[SBK_QSTRING_IDX], (pyIn)))) {
        PyErr_SetString(PyExc_TypeError, "wrong type attributed to 'title', 'QString' or convertible type expected");
        return -1;
    }

    auto &cppOut_ptr = cppSelf->title;
    pythonToCpp(pyIn, &cppOut_ptr);

    return 0;
}

// Getters and Setters for QHelpLink
static PyGetSetDef Sbk_QHelpLink_getsetlist[] = {
    {const_cast<char *>("url"), Sbk_QHelpLink_get_url, Sbk_QHelpLink_set_url},
    {const_cast<char *>("title"), Sbk_QHelpLink_get_title, Sbk_QHelpLink_set_title},
    {nullptr} // Sentinel
};

} // extern "C"

static int Sbk_QHelpLink_traverse(PyObject *self, visitproc visit, void *arg)
{
    return SbkObject_TypeF()->tp_traverse(self, visit, arg);
}
static int Sbk_QHelpLink_clear(PyObject *self)
{
    return reinterpret_cast<PyTypeObject *>(SbkObject_TypeF())->tp_clear(self);
}
// Class Definition -----------------------------------------------
extern "C" {
static PyTypeObject *_Sbk_QHelpLink_Type = nullptr;
static PyTypeObject *Sbk_QHelpLink_TypeF(void)
{
    return _Sbk_QHelpLink_Type;
}

static PyType_Slot Sbk_QHelpLink_slots[] = {
    {Py_tp_base,        nullptr}, // inserted by introduceWrapperType
    {Py_tp_dealloc,     reinterpret_cast<void *>(&SbkDeallocWrapper)},
    {Py_tp_repr,        nullptr},
    {Py_tp_hash,        nullptr},
    {Py_tp_call,        nullptr},
    {Py_tp_str,         nullptr},
    {Py_tp_getattro,    nullptr},
    {Py_tp_setattro,    nullptr},
    {Py_tp_traverse,    reinterpret_cast<void *>(Sbk_QHelpLink_traverse)},
    {Py_tp_clear,       reinterpret_cast<void *>(Sbk_QHelpLink_clear)},
    {Py_tp_richcompare, nullptr},
    {Py_tp_iter,        nullptr},
    {Py_tp_iternext,    nullptr},
    {Py_tp_methods,     reinterpret_cast<void *>(Sbk_QHelpLink_methods)},
    {Py_tp_getset,      reinterpret_cast<void *>(Sbk_QHelpLink_getsetlist)},
    {Py_tp_init,        reinterpret_cast<void *>(Sbk_QHelpLink_Init)},
    {Py_tp_new,         reinterpret_cast<void *>(SbkObjectTpNew)},
    {0, nullptr}
};
static PyType_Spec Sbk_QHelpLink_spec = {
    "2:PySide6.QtHelp.QHelpLink",
    sizeof(SbkObject),
    0,
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
    Sbk_QHelpLink_slots
};

} //extern "C"


// Type conversion functions.

// Python to C++ pointer conversion - returns the C++ object of the Python wrapper (keeps object identity).
static void QHelpLink_PythonToCpp_QHelpLink_PTR(PyObject *pyIn, void *cppOut)
{
    Shiboken::Conversions::pythonToCppPointer(Sbk_QHelpLink_TypeF(), pyIn, cppOut);
}
static PythonToCppFunc is_QHelpLink_PythonToCpp_QHelpLink_PTR_Convertible(PyObject *pyIn)
{
    if (pyIn == Py_None)
        return Shiboken::Conversions::nonePythonToCppNullPtr;
    if (PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(Sbk_QHelpLink_TypeF())))
        return QHelpLink_PythonToCpp_QHelpLink_PTR;
    return {};
}

// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).
static PyObject *QHelpLink_PTR_CppToPython_QHelpLink(const void *cppIn)
{
    auto pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn));
    if (pyOut) {
        Py_INCREF(pyOut);
        return pyOut;
    }
    bool changedTypeName = false;
    auto tCppIn = reinterpret_cast<const ::QHelpLink *>(cppIn);
    const char *typeName = typeid(*tCppIn).name();
    auto sbkType = Shiboken::ObjectType::typeForTypeName(typeName);
    if (sbkType && Shiboken::ObjectType::hasSpecialCastFunction(sbkType)) {
        typeName = typeNameOf(tCppIn);
        changedTypeName = true;
    }
    PyObject *result = Shiboken::Object::newObject(Sbk_QHelpLink_TypeF(), const_cast<void *>(cppIn), false, /* exactType */ changedTypeName, typeName);
    if (changedTypeName)
        delete [] typeName;
    return result;
}

// C++ to Python copy conversion.
static PyObject *QHelpLink_COPY_CppToPython_QHelpLink(const void *cppIn)
{
    return Shiboken::Object::newObject(Sbk_QHelpLink_TypeF(), new ::QHelpLink(*reinterpret_cast<const ::QHelpLink *>(cppIn)), true, true);
}

// Python to C++ copy conversion.
static void QHelpLink_PythonToCpp_QHelpLink_COPY(PyObject *pyIn, void *cppOut)
{
    *reinterpret_cast<::QHelpLink *>(cppOut) = *reinterpret_cast< ::QHelpLink *>(Shiboken::Conversions::cppPointer(SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX], reinterpret_cast<SbkObject *>(pyIn)));
}
static PythonToCppFunc is_QHelpLink_PythonToCpp_QHelpLink_COPY_Convertible(PyObject *pyIn)
{
    if (PyObject_TypeCheck(pyIn, reinterpret_cast<PyTypeObject *>(Sbk_QHelpLink_TypeF())))
        return QHelpLink_PythonToCpp_QHelpLink_COPY;
    return {};
}

// The signatures string for the functions.
// Multiple signatures have their index "n:" in front.
static const char *QHelpLink_SignatureStrings[] = {
    "1:PySide6.QtHelp.QHelpLink(self)",
    "0:PySide6.QtHelp.QHelpLink(self,QHelpLink:PySide6.QtHelp.QHelpLink)",
    "PySide6.QtHelp.QHelpLink.__copy__()",
    nullptr}; // Sentinel

void init_QHelpLink(PyObject *module)
{
    _Sbk_QHelpLink_Type = Shiboken::ObjectType::introduceWrapperType(
        module,
        "QHelpLink",
        "QHelpLink",
        &Sbk_QHelpLink_spec,
        &Shiboken::callCppDestructor< ::QHelpLink >,
        0,
        0,
        0);
    auto *pyType = Sbk_QHelpLink_TypeF(); // references _Sbk_QHelpLink_Type
    InitSignatureStrings(pyType, QHelpLink_SignatureStrings);
    SbkObjectType_SetPropertyStrings(reinterpret_cast<PyTypeObject *>(_Sbk_QHelpLink_Type), Sbk_QHelpLink_PropertyStrings);
    SbkPySide6_QtHelpTypes[SBK_QHELPLINK_IDX]
        = Sbk_QHelpLink_TypeF();

    // Register Converter
    SbkConverter *converter = Shiboken::Conversions::createConverter(Sbk_QHelpLink_TypeF(),
        QHelpLink_PythonToCpp_QHelpLink_PTR,
        is_QHelpLink_PythonToCpp_QHelpLink_PTR_Convertible,
        QHelpLink_PTR_CppToPython_QHelpLink,
        QHelpLink_COPY_CppToPython_QHelpLink);

    Shiboken::Conversions::registerConverterName(converter, "QHelpLink");
    Shiboken::Conversions::registerConverterName(converter, "QHelpLink*");
    Shiboken::Conversions::registerConverterName(converter, "QHelpLink&");
    Shiboken::Conversions::registerConverterName(converter, typeid(::QHelpLink).name());

    // Add Python to C++ copy (value, not pointer neither reference) conversion to type converter.
    Shiboken::Conversions::addPythonToCppValueConversion(converter,
        QHelpLink_PythonToCpp_QHelpLink_COPY,
        is_QHelpLink_PythonToCpp_QHelpLink_COPY_Convertible);

    qRegisterMetaType< ::QHelpLink >("QHelpLink");
}
