#include "LotoQmlPlugin.h"
#include "config.h"
#include "CANClient.h"

#include "../httpclient/HttpClient.h"
#include "../httpclient/HttpCardLogin.h"
#include "../httpclient/HttpGetJobTickets.h"
#include "../httpclient/HttpGetUserInfo.h"
#include "../httpclient/HttpGetWorkNodeDetail.h"
#include "../httpclient/HttpPasswordLogin.h"
#include "../httpclient/HttpUpdateNodeApproval.h"
#include "../httpclient/HttpUpdateUserInfo.h"
#include "../httpclient/HttpUpdateUserPassword.h"
#include "../httpclient/HttpFaceLogin.h"
#include "../httpclient/JobTicketsModel.h"
#include "../httpclient/UserInfoModel.h"
#include "../httpclient/WorkNodeFormModel.h"

#include "../interactive/InteractiveData.h"
#include "../interactive/InteractiveFace.h"
#include "../interactive/InteractiveHttp.h"
#include "../interactive/InteractiveTask.h"
#include "../interactive/InteractiveCAN.h"
#include "../interactive/ReturnKeyLockManager.h"

void LotoQmlPlugin::registerTypes(const char *uri)
{
    qDebug() << "[插件初始化] registerTypes被调用，模块名：" << uri;
//    int majorVersion = 1;
//    int minorVersion = 0;
//    // 注册模块
////    qmlRegisterModule(uri, majorVersion, minorVersion);
//    // 注册类型
//    qmlRegisterType<HttpClient>(uri, majorVersion, minorVersion, "HttpClient");
//    qmlRegisterType<HttpCardLogin>(uri, majorVersion, minorVersion, "HttpCardLogin");
//    qmlRegisterType<HttpGetJobTickets>(uri, majorVersion, minorVersion, "HttpGetJobTickets");
//    qmlRegisterType<HttpGetUserInfo>(uri, majorVersion, minorVersion, "HttpGetUserInfo");
//    qmlRegisterType<HttpGetWorkNodeDetail>(uri, majorVersion, minorVersion, "HttpGetWorkNodeDetail");
//    qmlRegisterType<HttpPasswordLogin>(uri, majorVersion, minorVersion, "HttpPasswordLogin");
//    qmlRegisterType<HttpUpdateNodeApproval>(uri, majorVersion, minorVersion, "HttpUpdateNodeApproval");
//    qmlRegisterType<HttpUpdateUserInfo>(uri, majorVersion, minorVersion, "HttpUpdateUserInfo");
//    qmlRegisterType<HttpUpdateUserPassword>(uri, majorVersion, minorVersion, "HttpUpdateUserPassword");
//    // 注册不可实例化类型, 枚举
////    qmlRegisterUncreatableType(uri, majorVersion, minorVersion, "", "");
//    // 注册单例对象
//    qmlRegisterSingletonType<JobTicketModel>(uri, majorVersion, minorVersion, "JobTicketModel", &JobTicketModel::create);
//    qmlRegisterSingletonType<UserInfoModel>(uri, majorVersion, minorVersion, "UserInfoModel", &UserInfoModel::create);
//    qmlRegisterSingletonType<WorkNodeFormModel>(uri, majorVersion, minorVersion, "WorkNodeFormModel", &WorkNodeFormModel::create);
}

void LotoQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
{
    QQmlExtensionPlugin::initializeEngine(engine, uri);
}

void LotoQmlTypes::registerTypes()
{
    const char* uri = Config()->lotoQmlModuleName;
    int majorVersion = 1;
    int minorVersion = 0;
    // 注册模块
    qmlRegisterModule(uri, majorVersion, minorVersion);

    qRegisterMetaType<QMap<int, QString>>("QMap<int, QString>");
    qRegisterMetaType<QVariantMap>("QVariantMap");
    qRegisterMetaType<QVariant>("QVariant");

    // 注册类型
    qmlRegisterType<HttpClient>(uri, majorVersion, minorVersion, "HttpClient");
    qmlRegisterType<HttpCardLogin>(uri, majorVersion, minorVersion, "HttpCardLogin");
    qmlRegisterType<HttpGetJobTickets>(uri, majorVersion, minorVersion, "HttpGetJobTickets");
    qmlRegisterType<HttpGetUserInfo>(uri, majorVersion, minorVersion, "HttpGetUserInfo");
    qmlRegisterType<HttpGetWorkNodeDetail>(uri, majorVersion, minorVersion, "HttpGetWorkNodeDetail");
    qmlRegisterType<HttpPasswordLogin>(uri, majorVersion, minorVersion, "HttpPasswordLogin");
    qmlRegisterType<HttpUpdateNodeApproval>(uri, majorVersion, minorVersion, "HttpUpdateNodeApproval");
    qmlRegisterType<HttpUpdateUserInfo>(uri, majorVersion, minorVersion, "HttpUpdateUserInfo");
    qmlRegisterType<HttpUpdateUserPassword>(uri, majorVersion, minorVersion, "HttpUpdateUserPassword");
    qmlRegisterType<HttpFaceLogin>(uri, majorVersion, minorVersion, "HttpFaceLogin");

    qmlRegisterType<CANClient>(uri, majorVersion, minorVersion, "CANClient");
    qRegisterMetaType<CANKeyBaseStatus>("CANKeyBaseStatus");
    qRegisterMetaType<CANKeyBaseControlStatus>("CANKeyBaseControlStatus");
    qRegisterMetaType<CANLockControlStatus>("CANLockControlStatus");
    qRegisterMetaType<CANLocksControl>("CANLocksControl");
    qRegisterMetaType<CANSingleLockStatus>("CANSingleLockStatus");
    qRegisterMetaType<CANKeyRFIDStatus>("CANKeyRFIDStatus");
    qRegisterMetaType<CANLockRFIDStatus>("CANLockRFIDStatus");
    qRegisterMetaType<CANKeyBaseChargeStatus>("CANKeyBaseChargeStatus");
    // 注册不可实例化类型, 枚举
//    qmlRegisterUncreatableType(uri, majorVersion, minorVersion, "", "");
    // 注册单例对象
    qmlRegisterSingletonType<JobTicketModel>(uri, majorVersion, minorVersion, "JobTicketModel", &JobTicketModel::create);
    qmlRegisterSingletonType<UserInfoModel>(uri, majorVersion, minorVersion, "UserInfoModel", &UserInfoModel::create);
    qmlRegisterSingletonType<WorkNodeFormModel>(uri, majorVersion, minorVersion, "WorkNodeFormModel", &WorkNodeFormModel::create);
    qmlRegisterSingletonType<InteractiveData>(uri, majorVersion, minorVersion, "InteractiveData", &InteractiveData::create);

    qmlRegisterSingletonType<InteractiveCAN>(uri, majorVersion, minorVersion, "InteractiveCAN", &InteractiveCAN::create);
    qmlRegisterSingletonType<InteractiveFace>(uri, majorVersion, minorVersion, "InteractiveFace", &InteractiveFace::create);

    // 注册归还钥匙和锁管理器
    qmlRegisterSingletonType<ReturnKeyLockManager>(uri, majorVersion, minorVersion, "ReturnKeyLockManager", &ReturnKeyLockManager::create);
}
