
// Workaround to access protected functions
#ifndef protected
#  define protected public
#endif

// default includes
#include <shiboken.h>
#include <sbkpep.h>
#include <sbkpepbuffer.h>

#define PYSIDE6_COMOPT_COMPRESS 1

#ifndef QT_NO_VERSION_TAGGING
#  define QT_NO_VERSION_TAGGING
#endif
#include <QtCore/QDebug>
#include <pysideqenum.h>
#include <pysideutils.h>
#include <feature_select.h>
QT_WARNING_DISABLE_DEPRECATED


// module include
#include "akonadicore_python.h"

// main header
#include "akonadi_selectionproxymodel_wrapper.h"

// Argument includes
#include <qitemselectionmodel.h>
#include <qobject.h>
#include <qobjectdefs.h>

#include <cctype>
#include <cstring>
#include <iterator>
#include <type_traits>
#include <typeinfo>

using namespace Akonadi;

extern "C" {
static PyTypeObject *Sbk_Akonadi_SelectionProxyModel_TypeF(void)
{
    return SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX].type;
}
} // extern "C"

// Native ---------------------------------------------------------

SelectionProxyModelWrapper::SelectionProxyModelWrapper(::QItemSelectionModel * selectionModel, ::QObject * parent) : Akonadi::SelectionProxyModel(selectionModel, parent)
{
}

SelectionProxyModelWrapper::~SelectionProxyModelWrapper()
{
    auto *wrapper = Shiboken::BindingManager::instance().retrieveWrapper(this, Sbk_Akonadi_SelectionProxyModel_TypeF());
    Shiboken::Object::destroy(wrapper, this);
}

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

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

    SelectionProxyModelWrapper *cptr{};
    Shiboken::AutoDecRef errInfo{};
    Shiboken::PythonContextMarker pcm;
    int overloadId = -1;
    [[maybe_unused]] Shiboken::Conversions::PythonToCppConversion pythonToCpp[2];
    const Py_ssize_t numArgs = PyTuple_Size(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {nullptr, nullptr};

    // invalid argument lengths
    errInfo.reset(Shiboken::checkInvalidArgumentCount(numArgs, 1, 2));
    if (!errInfo.isNull())
        return Shiboken::returnWrongArguments_MinusOne(args, "__init__", errInfo, SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX]);

    if (PyArg_ParseTuple(args, "|OO:SelectionProxyModel", &(pyArgs[0]), &(pyArgs[1])) == 0)
        return -1;


    // Overloaded function decisor
    // 0: SelectionProxyModel::SelectionProxyModel(QItemSelectionModel*,QObject*=)
    if (numArgs >= 1
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppPointerConversion(Shiboken::Module::get(SbkPySide6_QtCoreTypeStructs[SBK_QItemSelectionModel_IDX]), (pyArgs[0])))) {
        if (numArgs == 1) {
            overloadId = 0; // SelectionProxyModel(QItemSelectionModel*,QObject*)
        } else if (numArgs >= 2
            && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppPointerConversion(Shiboken::Module::get(SbkPySide6_QtCoreTypeStructs[SBK_QObject_IDX]), (pyArgs[1])))) {
            overloadId = 0; // SelectionProxyModel::SelectionProxyModel(QItemSelectionModel*,QObject*=)
        }
    }

    // Function signature not found.
    if (overloadId == -1)
        return Shiboken::returnWrongArguments_MinusOne(args, "__init__", SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX]);

    // Resolve keyword arguments
    {
        if (kwds != nullptr && PyDict_Size(kwds) > 0) {
            static const Shiboken::ArgumentNameIndexMapping mapping[1] = {{"parent", 1}};
            if (!Shiboken::parseKeywordArguments(kwds, mapping, 1, errInfo, pyArgs)
                || (pyArgs[1] != nullptr && !((pythonToCpp[1] = Shiboken::Conversions::pythonToCppPointerConversion(Shiboken::Module::get(SbkPySide6_QtCoreTypeStructs[SBK_QObject_IDX]), (pyArgs[1])))))) {
                Py_XINCREF(errInfo.object());
                return Shiboken::returnWrongArguments_MinusOne(args, "__init__", errInfo, SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX]);
            }
        }
    }

    // PyMI support
    Shiboken::callInheritedInit(self, args, errInfo.isNull() ? kwds : errInfo.object(), SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX]);
    if (Shiboken::Errors::occurred() != nullptr)
        return -1;

    // Call function/method
    {
        if (!Shiboken::Object::isValid(pyArgs[0]))
            return -1;
        ::QItemSelectionModel *cppArg0;
        pythonToCpp[0](pyArgs[0], &cppArg0);
        if (!Shiboken::Object::isValid(pyArgs[1]))
            return -1;
        ::QObject *cppArg1 = nullptr;
        if (pythonToCpp[1])
            pythonToCpp[1](pyArgs[1], &cppArg1);

        if (Shiboken::Errors::occurred() == nullptr) {
            // SelectionProxyModel::SelectionProxyModel(QItemSelectionModel*,QObject*=)
            cptr = new SelectionProxyModelWrapper(cppArg0, cppArg1);
        }
    }

    if (Shiboken::Errors::occurred() != nullptr || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< Akonadi::SelectionProxyModel >(), cptr)) {
        delete cptr;
        return -1;
    }
    if (cptr == nullptr)
        return Shiboken::returnWrongArguments_MinusOne(args, "__init__", SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX]);

    Shiboken::Object::setValidCpp(sbkSelf, true);
    Shiboken::Object::setHasCppWrapper(sbkSelf, true);
    Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);


    return 1;
}


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

static PyMethodDef Sbk_Akonadi_SelectionProxyModel_methods[] = {
    {nullptr, nullptr, 0, nullptr} // Sentinel
};

} // extern "C"

static int Sbk_Akonadi_SelectionProxyModel_traverse(PyObject *self, visitproc visit, void *arg)
{
    auto traverseProc = reinterpret_cast<traverseproc>(PyType_GetSlot(SbkObject_TypeF(), Py_tp_traverse));
    ;
    return traverseProc(self, visit, arg);
}
static int Sbk_Akonadi_SelectionProxyModel_clear(PyObject *self)
{
    auto clearProc = reinterpret_cast<inquiry>(PyType_GetSlot(SbkObject_TypeF(), Py_tp_clear));
    ;
    return clearProc(self);
}

// Class Definition -----------------------------------------------
extern "C" {

static PyType_Slot Sbk_Akonadi_SelectionProxyModel_slots[] = {
    {Py_tp_base,        nullptr}, // inserted by introduceWrapperType
    {Py_tp_dealloc,     reinterpret_cast<void *>(&SbkDeallocWrapper)},
    {Py_tp_traverse,    reinterpret_cast<void *>(Sbk_Akonadi_SelectionProxyModel_traverse)},
    {Py_tp_clear,       reinterpret_cast<void *>(Sbk_Akonadi_SelectionProxyModel_clear)},
    {Py_tp_methods,     reinterpret_cast<void *>(Sbk_Akonadi_SelectionProxyModel_methods)},
    {Py_tp_init,        reinterpret_cast<void *>(Sbk_Akonadi_SelectionProxyModel_Init)},
    {Py_tp_new,         reinterpret_cast<void *>(SbkObject_tp_new)},
    {0, nullptr}
};
static PyType_Spec Sbk_Akonadi_SelectionProxyModel_spec = {
    "1:AkonadiCore.Akonadi.SelectionProxyModel",
    sizeof(SbkObject),
    0,
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
    Sbk_Akonadi_SelectionProxyModel_slots
};

} //extern "C"

// Type conversion functions.

// Python to C++ pointer conversion - returns the C++ object of the Python wrapper (keeps object identity).
static void SelectionProxyModel_PythonToCpp_SelectionProxyModel_PTR(PyObject *pyIn, void *cppOut)
{
    Shiboken::Conversions::pythonToCppPointer(Sbk_Akonadi_SelectionProxyModel_TypeF(), pyIn, cppOut);
}
static PythonToCppFunc is_SelectionProxyModel_PythonToCpp_SelectionProxyModel_PTR_Convertible(PyObject *pyIn)
{
    if (pyIn == Py_None)
        return Shiboken::Conversions::nonePythonToCppNullPtr;
    if (PyObject_TypeCheck(pyIn, Sbk_Akonadi_SelectionProxyModel_TypeF()))
        return SelectionProxyModel_PythonToCpp_SelectionProxyModel_PTR;
    return {};
}

// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).
static PyObject *SelectionProxyModel_PTR_CppToPython_SelectionProxyModel(const void *cppIn)
{
    auto *pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn, Sbk_Akonadi_SelectionProxyModel_TypeF()));
    if (pyOut) {
        Py_INCREF(pyOut);
        return pyOut;
    }
    auto *tCppIn = reinterpret_cast<const ::Akonadi::SelectionProxyModel *>(cppIn);
    const char *typeName = typeid(*tCppIn).name();
    return Shiboken::Object::newObjectForPointer(Sbk_Akonadi_SelectionProxyModel_TypeF(), const_cast<void *>(cppIn), false, typeName);

}

// The signatures string for the functions.
// Multiple signatures have their index "n:" in front.
#if PYSIDE6_COMOPT_COMPRESS == 0
static const char *Akonadi_SelectionProxyModel_SignatureStrings[] = {
    "AkonadiCore.Akonadi.SelectionProxyModel(self,selectionModel:PySide6.QtCore.QItemSelectionModel,parent:PySide6.QtCore.QObject=nullptr)",
    nullptr}; // Sentinel
#else
static constexpr size_t Akonadi_SelectionProxyModel_SignatureByteSize = 98;
static constexpr uint8_t Akonadi_SelectionProxyModel_SignatureBytes[98] = {
    0x78, 0xda, 0x73, 0xcc, 0xce, 0xcf, 0x4b, 0x4c, 0xc9, 0x74, 0xce, 0x2f, 0x4a, 0xd5, 0x73, 0x84,
    0xb0, 0xf5, 0x82, 0x53, 0x73, 0x52, 0x93, 0x4b, 0x32, 0xf3, 0xf3, 0x02, 0x8a, 0xf2, 0x2b, 0x2a,
    0x7d, 0xf3, 0x53, 0x52, 0x73, 0x34, 0x8a, 0x53, 0x73, 0xd2, 0x74, 0x8a, 0x61, 0x12, 0x60, 0x31,
    0xab, 0x80, 0xca, 0xe0, 0xcc, 0x94, 0x54, 0x33, 0xbd, 0xc0, 0x12, 0xb0, 0xf6, 0x40, 0xcf, 0x92,
    0xd4, 0xdc, 0x60, 0x14, 0x25, 0x3a, 0x05, 0x89, 0x45, 0xa9, 0x79, 0x25, 0x18, 0x2a, 0xfd, 0x93,
    0xb2, 0x80, 0xaa, 0x6c, 0xf3, 0x4a, 0x73, 0x72, 0x0a, 0x4a, 0x8a, 0x34, 0xb9, 0x00, 0x54, 0x65,
    0x31, 0xe8
};
#endif

PyTypeObject *init_Akonadi_SelectionProxyModel(PyObject *enclosingClass)
{
    auto &typeStruct = SbkAkonadiCoreTypeStructs[SBK_Akonadi_SelectionProxyModel_IDX];
    if (typeStruct.type != nullptr)
        return typeStruct.type;

    auto *base1 = SbkObject_TypeF();
    Shiboken::AutoDecRef Sbk_Akonadi_SelectionProxyModel_Type_bases(PyTuple_Pack(1, base1));

    PyTypeObject *pyType = Shiboken::ObjectType::introduceWrapperType(
        enclosingClass,
        "SelectionProxyModel",
        "Akonadi::SelectionProxyModel*",
        &Sbk_Akonadi_SelectionProxyModel_spec,
        &Shiboken::callCppDestructor< Akonadi::SelectionProxyModel >,
        Sbk_Akonadi_SelectionProxyModel_Type_bases.object(),
        Shiboken::ObjectType::WrapperFlags::InnerClass);
#if PYSIDE6_COMOPT_COMPRESS == 0
    InitSignatureStrings(pyType, Akonadi_SelectionProxyModel_SignatureStrings);
#else
    InitSignatureBytes(pyType, Akonadi_SelectionProxyModel_SignatureBytes, Akonadi_SelectionProxyModel_SignatureByteSize);
#endif
    SbkObjectType_SetPropertyStrings(pyType, Sbk_Akonadi_SelectionProxyModel_PropertyStrings);
    typeStruct.type = pyType;

    // Register Converter
    SbkConverter *converter = Shiboken::Conversions::createConverter(pyType,
        SelectionProxyModel_PythonToCpp_SelectionProxyModel_PTR,
        is_SelectionProxyModel_PythonToCpp_SelectionProxyModel_PTR_Convertible,
        SelectionProxyModel_PTR_CppToPython_SelectionProxyModel);

    Shiboken::Conversions::registerConverterName(converter, "Akonadi::SelectionProxyModel");
    Shiboken::Conversions::registerConverterName(converter, "Akonadi::SelectionProxyModel*");
    Shiboken::Conversions::registerConverterName(converter, "Akonadi::SelectionProxyModel&");
    Shiboken::Conversions::registerConverterAlias(converter, "SelectionProxyModel");
    Shiboken::Conversions::registerConverterAlias(converter, "SelectionProxyModel*");
    Shiboken::Conversions::registerConverterAlias(converter, "SelectionProxyModel&");
    Shiboken::Conversions::registerConverterName(converter, typeid(::Akonadi::SelectionProxyModel).name());
    Shiboken::Conversions::registerConverterName(converter, typeid(SelectionProxyModelWrapper).name());

    qRegisterMetaType< ::Akonadi::SelectionProxyModel *>();

    return pyType;
}
