
// 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_differencesalgorithminterface_wrapper.h"

// Argument includes
#include <abstractdifferencesreporter.h>
#include <item.h>

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

using namespace Akonadi;

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

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

void DifferencesAlgorithmInterfaceWrapper::resetPyMethodCache()
{
    std::fill(m_PyMethodCache.begin(), m_PyMethodCache.end(), nullptr);
}

DifferencesAlgorithmInterfaceWrapper::DifferencesAlgorithmInterfaceWrapper()
{
}

void DifferencesAlgorithmInterfaceWrapper::compare(::Akonadi::AbstractDifferencesReporter * reporter, const ::Akonadi::Item & leftItem, const ::Akonadi::Item & rightItem)
{
    static const char *funcName = "compare";
    static PyObject *nameCache[2] = {};
    Shiboken::GilState gil(false);
    Shiboken::AutoDecRef pyOverride(Sbk_GetPyOverride(this, Sbk_Akonadi_DifferencesAlgorithmInterface_TypeF(), gil, funcName, m_PyMethodCache[0], nameCache));
    if (pyOverride.isNull()) {
        gil.acquire();
        Shiboken::Errors::setPureVirtualMethodError("DifferencesAlgorithmInterface.compare");
        return;
    }
    sbk_o_compare("DifferencesAlgorithmInterface", funcName, gil, pyOverride, reporter, leftItem, rightItem);
}

void DifferencesAlgorithmInterfaceWrapper::sbk_o_compare([[maybe_unused]] const char *ownerClassName, [[maybe_unused]] const char *funcName, [[maybe_unused]] Shiboken::GilState &gil, [[maybe_unused]] const Shiboken::AutoDecRef &pyOverride, [[maybe_unused]] ::Akonadi::AbstractDifferencesReporter * reporter, [[maybe_unused]] const ::Akonadi::Item & leftItem, [[maybe_unused]] const ::Akonadi::Item & rightItem)
{
#if !defined(PYPY_VERSION) && (!defined(Py_LIMITED_API) || Py_LIMITED_API >= 0x030C0000)
    PyObject *pyArgArray[3] = {
        Shiboken::Conversions::pointerToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_AbstractDifferencesReporter_IDX]), reporter),
        Shiboken::Conversions::copyToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), &leftItem),
        Shiboken::Conversions::copyToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), &rightItem)
    };
#else
    Shiboken::AutoDecRef pyArgs(Py_BuildValue("(NNN)",
        Shiboken::Conversions::pointerToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_AbstractDifferencesReporter_IDX]), reporter),
        Shiboken::Conversions::copyToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), &leftItem),
        Shiboken::Conversions::copyToPython(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), &rightItem)
    ));
#endif

#if !defined(PYPY_VERSION) && (!defined(Py_LIMITED_API) || Py_LIMITED_API >= 0x030C0000)
    Shiboken::AutoDecRef pyResult(PyObject_Vectorcall(pyOverride, pyArgArray, 3, nullptr));
    Py_DECREF(pyArgArray[0]);
    Py_DECREF(pyArgArray[1]);
    Py_DECREF(pyArgArray[2]);
#else
    Shiboken::AutoDecRef pyResult(PyObject_Call(pyOverride, pyArgs, nullptr));
#endif
    if (pyResult.isNull()) {
        // An error happened in python code!
        Shiboken::Errors::storePythonOverrideErrorOrPrint(ownerClassName, funcName);
        return;
    }
}

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

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

extern "C" {
static int
Sbk_Akonadi_DifferencesAlgorithmInterface_Init(PyObject *self, [[maybe_unused]] PyObject *args, [[maybe_unused]] PyObject *kwds)
{
    auto *sbkSelf = reinterpret_cast<SbkObject *>(self);
    PyTypeObject *type = self->ob_type;
    PyTypeObject *myType = Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_DifferencesAlgorithmInterface_IDX]);
    if (type == myType) {
        Shiboken::Errors::setInstantiateAbstractClass("Akonadi::DifferencesAlgorithmInterface");
        return -1;
    }

    PySide::Feature::Select(self);
    if (Shiboken::Object::isUserType(self) && !Shiboken::ObjectType::canCallConstructor(self->ob_type, Shiboken::SbkType< ::Akonadi::DifferencesAlgorithmInterface >()))
        return -1;

    DifferencesAlgorithmInterfaceWrapper *cptr{};
    Shiboken::PythonContextMarker pcm;


    // PyMI support
    Shiboken::callInheritedInit(self, args, kwds, SbkAkonadiCoreTypeStructs[SBK_Akonadi_DifferencesAlgorithmInterface_IDX]);
    if (Shiboken::Errors::occurred() != nullptr)
        return -1;

    // Call function/method
    {

        // DifferencesAlgorithmInterface::DifferencesAlgorithmInterface()
        cptr = new DifferencesAlgorithmInterfaceWrapper();
    }

    if (Shiboken::Errors::occurred() != nullptr || !Shiboken::Object::setCppPointer(sbkSelf, Shiboken::SbkType< Akonadi::DifferencesAlgorithmInterface >(), cptr)) {
        delete cptr;
        return -1;
    }
    Shiboken::Object::setValidCpp(sbkSelf, true);
    Shiboken::Object::setHasCppWrapper(sbkSelf, true);
    Shiboken::BindingManager::instance().registerWrapper(sbkSelf, cptr);


    return 1;
}

static PyObject *Sbk_Akonadi_DifferencesAlgorithmInterfaceFunc_compare(PyObject *self, PyObject *args)
{
    if (!Shiboken::Object::isValid(self))
        return {};
    [[maybe_unused]] auto *cppSelf = reinterpret_cast< ::Akonadi::DifferencesAlgorithmInterface *>(Shiboken::Conversions::cppPointer(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_DifferencesAlgorithmInterface_IDX]), reinterpret_cast<SbkObject *>(self)));
    Shiboken::AutoDecRef errInfo{};
    Shiboken::PythonContextMarker pcm;
    int overloadId = -1;
    [[maybe_unused]] Shiboken::Conversions::PythonToCppConversion pythonToCpp[3];
    const Py_ssize_t numArgs = PyTuple_Size(args);
    SBK_UNUSED(numArgs)
    PyObject *pyArgs[] = {nullptr, nullptr, nullptr};

    // invalid argument lengths

    if (PyArg_UnpackTuple(args, "compare", 3, 3, &(pyArgs[0]), &(pyArgs[1]), &(pyArgs[2])) == 0)
        return {};


    // Overloaded function decisor
    // 0: DifferencesAlgorithmInterface::compare(Akonadi::AbstractDifferencesReporter*,const Akonadi::Item&,const Akonadi::Item&)
    if (numArgs == 3
        && (pythonToCpp[0] = Shiboken::Conversions::pythonToCppPointerConversion(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_AbstractDifferencesReporter_IDX]), (pyArgs[0])))
        && (pythonToCpp[1] = Shiboken::Conversions::pythonToCppReferenceConversion(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), (pyArgs[1])))
        && (pythonToCpp[2] = Shiboken::Conversions::pythonToCppReferenceConversion(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_Item_IDX]), (pyArgs[2])))) {
        overloadId = 0; // DifferencesAlgorithmInterface::compare(Akonadi::AbstractDifferencesReporter*,const Akonadi::Item&,const Akonadi::Item&)
    }

    // Function signature not found.
    if (overloadId == -1)
        return Shiboken::returnWrongArguments(args, "compare", SbkAkonadiCoreTypeStructs[SBK_Akonadi_DifferencesAlgorithmInterface_IDX]);

    // Call function/method
    {
        if (!Shiboken::Object::isValid(pyArgs[0]))
            return {};
        ::Akonadi::AbstractDifferencesReporter *cppArg0;
        pythonToCpp[0](pyArgs[0], &cppArg0);
        if (!Shiboken::Object::isValid(pyArgs[1]))
            return {};
        ::Akonadi::Item cppArg1_local;
        ::Akonadi::Item *cppArg1 = &cppArg1_local;
        if (pythonToCpp[1].isValue())
            pythonToCpp[1](pyArgs[1], &cppArg1_local);
        else
            pythonToCpp[1](pyArgs[1], &cppArg1);

        if (!Shiboken::Object::isValid(pyArgs[2]))
            return {};
        ::Akonadi::Item cppArg2_local;
        ::Akonadi::Item *cppArg2 = &cppArg2_local;
        if (pythonToCpp[2].isValue())
            pythonToCpp[2](pyArgs[2], &cppArg2_local);
        else
            pythonToCpp[2](pyArgs[2], &cppArg2);


        if (Shiboken::Errors::occurred() == nullptr) {
            // DifferencesAlgorithmInterface::compare(Akonadi::AbstractDifferencesReporter*,const Akonadi::Item&,const Akonadi::Item&)
            if (Shiboken::Object::hasCppWrapper(reinterpret_cast<SbkObject *>(self))) {
                Shiboken::Errors::setPureVirtualMethodError("DifferencesAlgorithmInterface.compare");
                return {};
            }
            cppSelf->compare(cppArg0, *cppArg1, *cppArg2);
        }
    }

     return Sbk_ReturnFromPython_None();
}


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

static PyMethodDef Sbk_Akonadi_DifferencesAlgorithmInterface_methods[] = {
    {"compare", reinterpret_cast<PyCFunction>(Sbk_Akonadi_DifferencesAlgorithmInterfaceFunc_compare), METH_VARARGS, nullptr},
    {nullptr, nullptr, 0, nullptr} // Sentinel
};

static int Sbk_Akonadi_DifferencesAlgorithmInterface_setattro(PyObject *self, PyObject *name, PyObject *value)
{
    PySide::Feature::Select(self);
    if (value != nullptr && PyCallable_Check(value) != 0) {
        auto plain_inst = reinterpret_cast< ::Akonadi::DifferencesAlgorithmInterface *>(Shiboken::Conversions::cppPointer(Shiboken::Module::get(SbkAkonadiCoreTypeStructs[SBK_Akonadi_DifferencesAlgorithmInterface_IDX]), reinterpret_cast<SbkObject *>(self)));
        auto *inst = dynamic_cast<DifferencesAlgorithmInterfaceWrapper *>(plain_inst);
        if (inst != nullptr)
            inst->resetPyMethodCache();
    }
    return PyObject_GenericSetAttr(self, name, value);
}

} // extern "C"

static int Sbk_Akonadi_DifferencesAlgorithmInterface_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_DifferencesAlgorithmInterface_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_DifferencesAlgorithmInterface_slots[] = {
    {Py_tp_base,        nullptr}, // inserted by introduceWrapperType
    {Py_tp_dealloc,     reinterpret_cast<void *>(&SbkDeallocWrapper)},
    {Py_tp_setattro,    reinterpret_cast<void *>(Sbk_Akonadi_DifferencesAlgorithmInterface_setattro)},
    {Py_tp_traverse,    reinterpret_cast<void *>(Sbk_Akonadi_DifferencesAlgorithmInterface_traverse)},
    {Py_tp_clear,       reinterpret_cast<void *>(Sbk_Akonadi_DifferencesAlgorithmInterface_clear)},
    {Py_tp_methods,     reinterpret_cast<void *>(Sbk_Akonadi_DifferencesAlgorithmInterface_methods)},
    {Py_tp_init,        reinterpret_cast<void *>(Sbk_Akonadi_DifferencesAlgorithmInterface_Init)},
    {Py_tp_new,         reinterpret_cast<void *>(SbkObject_tp_new)},
    {0, nullptr}
};
static PyType_Spec Sbk_Akonadi_DifferencesAlgorithmInterface_spec = {
    "1:AkonadiCore.Akonadi.DifferencesAlgorithmInterface",
    sizeof(SbkObject),
    0,
    Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC,
    Sbk_Akonadi_DifferencesAlgorithmInterface_slots
};

} //extern "C"

// Type conversion functions.

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

// C++ to Python pointer conversion - tries to find the Python wrapper for the C++ object (keeps object identity).
static PyObject *DifferencesAlgorithmInterface_PTR_CppToPython_DifferencesAlgorithmInterface(const void *cppIn)
{
    auto *pyOut = reinterpret_cast<PyObject *>(Shiboken::BindingManager::instance().retrieveWrapper(cppIn, Sbk_Akonadi_DifferencesAlgorithmInterface_TypeF()));
    if (pyOut) {
        Py_INCREF(pyOut);
        return pyOut;
    }
    auto *tCppIn = reinterpret_cast<const ::Akonadi::DifferencesAlgorithmInterface *>(cppIn);
    const char *typeName = typeid(*tCppIn).name();
    return Shiboken::Object::newObjectForPointer(Sbk_Akonadi_DifferencesAlgorithmInterface_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_DifferencesAlgorithmInterface_SignatureStrings[] = {
    "AkonadiCore.Akonadi.DifferencesAlgorithmInterface(self)",
    "AkonadiCore.Akonadi.DifferencesAlgorithmInterface.compare(self,reporter:AkonadiCore.Akonadi.AbstractDifferencesReporter,leftItem:AkonadiCore.Akonadi.Item,rightItem:AkonadiCore.Akonadi.Item)",
    nullptr}; // Sentinel
#else
static constexpr size_t Akonadi_DifferencesAlgorithmInterface_SignatureByteSize = 117;
static constexpr uint8_t Akonadi_DifferencesAlgorithmInterface_SignatureBytes[117] = {
    0x78, 0xda, 0x95, 0x8c, 0x31, 0x0e, 0x83, 0x30, 0x10, 0x04, 0x7b, 0x5e, 0x12, 0x24, 0xcb, 0x0f,
    0x48, 0x77, 0x22, 0x0d, 0x6d, 0x7e, 0xe0, 0x98, 0x3d, 0xb0, 0x62, 0xfb, 0xd0, 0xf9, 0xfe, 0xaf,
    0x80, 0x48, 0x41, 0x81, 0x22, 0xa5, 0x5b, 0x69, 0x66, 0x96, 0xde, 0x52, 0xc3, 0x94, 0x06, 0x51,
    0x78, 0x3a, 0xb6, 0x7f, 0x24, 0x66, 0x28, 0x6a, 0x44, 0xa3, 0x3c, 0x8b, 0x26, 0x5b, 0xca, 0x58,
    0x0d, 0xca, 0x21, 0xe2, 0xd6, 0x90, 0xb9, 0xef, 0xe8, 0xdf, 0xce, 0x47, 0x29, 0x6b, 0xd0, 0xa3,
    0x77, 0x8a, 0x55, 0x74, 0x23, 0xf7, 0xab, 0x1f, 0x7a, 0x35, 0xd3, 0x10, 0xed, 0xf4, 0xf7, 0xfc,
    0xfa, 0x2e, 0x83, 0x6d, 0x34, 0x94, 0xcb, 0x70, 0x07, 0x4e, 0xd3, 0xbc, 0xfc, 0x56, 0xfa, 0xee,
    0x03, 0xf4, 0x6e, 0x5c, 0x7a
};
#endif

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

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

    PyTypeObject *pyType = Shiboken::ObjectType::introduceWrapperType(
        enclosingClass,
        "DifferencesAlgorithmInterface",
        "Akonadi::DifferencesAlgorithmInterface*",
        &Sbk_Akonadi_DifferencesAlgorithmInterface_spec,
        &Shiboken::callCppDestructor< Akonadi::DifferencesAlgorithmInterface >,
        Sbk_Akonadi_DifferencesAlgorithmInterface_Type_bases.object(),
        Shiboken::ObjectType::WrapperFlags::InnerClass);
#if PYSIDE6_COMOPT_COMPRESS == 0
    InitSignatureStrings(pyType, Akonadi_DifferencesAlgorithmInterface_SignatureStrings);
#else
    InitSignatureBytes(pyType, Akonadi_DifferencesAlgorithmInterface_SignatureBytes, Akonadi_DifferencesAlgorithmInterface_SignatureByteSize);
#endif
    SbkObjectType_SetPropertyStrings(pyType, Sbk_Akonadi_DifferencesAlgorithmInterface_PropertyStrings);
    typeStruct.type = pyType;

    // Register Converter
    SbkConverter *converter = Shiboken::Conversions::createConverter(pyType,
        DifferencesAlgorithmInterface_PythonToCpp_DifferencesAlgorithmInterface_PTR,
        is_DifferencesAlgorithmInterface_PythonToCpp_DifferencesAlgorithmInterface_PTR_Convertible,
        DifferencesAlgorithmInterface_PTR_CppToPython_DifferencesAlgorithmInterface);

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

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

    return pyType;
}
