#ifndef CONTROL_H
#define CONTROL_H

#include "global.h"
#include "hostwidget.h"
#include "fmp_settings.h"
#include <QObject>
#include <QApplication>
#include <QLibrary>
#include <QMutex>

class Control : public QObject
{
    Q_OBJECT

public:

    explicit Control(QObject *parent = 0);

    ~Control();

    void Start(const char *indata, char *outdata);

    void setIsinterrupt(bool isinterrupt);

#ifdef FM_TEST
    friend class TestSimphony;
#endif

signals:
    void Exits();

private:

    void CheckDllEnvironmentNormal();

    void CheckQsslSupportsSslError();

    void CheckQsslSupportsSslVersion();

    bool SendMessageBefore(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);

    bool SendMessageReady(const QJsonObject &json, QByteArray &outdata, QString &error, ReqType reqType);

    void SetResponseWithMessage(QString code, const QString &message);

    void RequestSign();

    bool GetRSA(QString &error);

    void RequestBusinessAction(ReqType type, QStringList list);

    bool GetJson(ReqType type, QJsonObject &json, const QByteArray array, QString &error);

    bool HttpPost(QString url, QByteArray &outdata, const QByteArray &indata, QString content, QString accept, QString &error, int timeout, ReqType reqType);

    bool InitPOSReqJsonObj(const char *indata);

    static bool IsValidCode(const QString &code);

public slots:

    void OnRequestWithType(ReqType type, QStringList list);

    void OnInterrupt();

private:

    QJsonObject _posReqJsonObj;
    QJsonObject _responseJsonObj;
    HostWidget *_widget;
    //确保exe结束后不会重新弹窗
    QMutex _lock;

    QString _fmId;

    bool _isinterrupt;

    FMPSettings _setting;

    int  _posPartnerRegion;
};

#endif // CONTROL_H
