//
// Created by chenjinyi on 2024/10/29.
//

#ifndef _ASP_CLIENT_H
#define _ASP_CLIENT_H
#include "AspClientDefine.h"
#include "AspDisplay.h"
#include "AspPlayer.h"
#include "AspAudio.h"
#include "AspSharedPtr.h"
#include <string>

namespace wuying {
namespace asp {

struct AspTicket {
    std::string ticket;
    std::string id;
    std::string user;
    std::string uuid;
    std::string systemType;
    uint8_t partner;
    bool isThumbnailEnable = false;
};

enum AspSystemStatus {
    SYS_UNKNOWN = 0,
    SYS_SUSPEND = 1,
    SYS_RESUME_SUSPEND = 2,
    SYS_SLEEP = 3,
    SYS_RESUME_SLEEP = 4,
};

enum AspMouseMode {
    ASP_MSMODE_SERVER = (1 << 0),
    ASP_MSMODE_CLIENT = (1 << 1),
    ASP_MSMODE_MASK = 0x3
};

enum AspImageQuality {
    ASP_IMAGE_QUALITY_LOSSLESS = 0,
    ASP_IMAGE_QUALITY_HIGH = 1,
    ASP_IMAGE_QUALITY_MEDIUM = 2,
    ASP_IMAGE_QUALITY_LOW = 3,
    ASP_IMAGE_QUALITY_AUTO = 4,
};

enum AspClipboardType {
    CLIPBOARD_NONE = 0,
    CLIPBOARD_UTF8_TEXT,
    CLIPBOARD_IMAGE_PNG,  /* All clients with image support should support this one */
    CLIPBOARD_IMAGE_BMP,  /* optional */
    CLIPBOARD_IMAGE_TIFF, /* optional */
    CLIPBOARD_IMAGE_JPG,  /* optional */
    CLIPBOARD_FILE,       /* optional, single file */
    CLIPBOARD_DIRECTORY,  /* optional, support directory recrusive */
    CLIPBOARD_HTML,
    CLIPBOARD_RTF,
    CLIPBOARD_XML_SPREAD_SHEET,
};

struct AspClipboardData {
    AspClipboardType type;
    uint8_t* data;
    uint32_t size;
};

enum ConnectEventType {
    EVENT_CONNECT_SUCCESS,
    EVENT_CONNECT_FAILED,
    EVENT_DISCONNECT_SUCCESS,
    EVENT_RECONNECT_START,
    EVENT_RECONNECT_FAILED
};

enum AspConnType {
    ASP_CONN_SOCKET = 0,
    ASP_CONN_SOCKPAIR = 1,
    ASP_CONN_PIPE = 2,
    ASP_CONN_SOCKET_UNIX = 3,
    ASP_CONN_END = ASP_CONN_PIPE,
};

struct ConnectEvent {
    ConnectEventType type;
    int reason;
};

class ASP_CLIENT_SDK_API IAspClientCallback : public AspRefCounted {
public:
    virtual void onThumbnailUpdate(void* buffer, uint32_t width, uint32_t height, AspImageFormat format) = 0;
    virtual void onConnectEvent(ConnectEvent &event) = 0;
};

class ASP_CLIENT_SDK_API IClipboardCallback : public AspRefCounted {
public:
    virtual void onClipboardRead(uint8_t selection, AspClipboardType type) = 0;
    virtual void onClipboardWrite(std::vector<AspClipboardData> dataV) = 0;
};

class ASP_CLIENT_SDK_API IShellCmdCallback : public AspRefCounted {
public:
    virtual void onReceiveStringData(const std::string& val) = 0;
    virtual void onReceiveRawData(const std::vector<uint8_t> val) = 0;
};

class ASP_CLIENT_SDK_API IStatisticCallback : public AspRefCounted  {
public:
    /**
     * Report performance statistic report periodically
     *
     * @param report        The JSON string content that represents latest performance statistic info
     */
    virtual void onStatisticReportUpdate(const std::string& report) = 0;
};

class ASP_CLIENT_SDK_API AspClient : public AspRefCounted {
public:
    static AspClient* create(AspTicket& ticket, wuying::asp::shared_ptr<IAspClientCallback> callback);
    static void destroy(AspClient* client);

    virtual void open() = 0;
    virtual void reopen(std::string& ticket) = 0;
    virtual void close(bool destroyClient = false) = 0;
    virtual void pause() = 0;
    virtual void resume() = 0;

    virtual void setSystemStatus(AspSystemStatus status) = 0;
    virtual void setGatewayOption(bool enable) = 0;
    virtual void setMouseMode(AspMouseMode mode) = 0;
    virtual void setVolume(int volumeValue) = 0;

    virtual bool isSupportTouchMode() = 0;

    virtual wuying::asp::shared_ptr<AspDisplay> addDisplay(wuying::asp::shared_ptr<IAspDisplayCallback> display) = 0;
    virtual void removeDisplay(wuying::asp::shared_ptr<AspDisplay> display) = 0;

    virtual void setThumbnailDisplay(uint32_t width, uint32_t height, int32_t fps) = 0;
    virtual void resumeThumbnailDisplay() = 0;
    virtual void suspendThumbnailDisplay() = 0;

    virtual void setGraphicsQuality(AspImageQuality quality) = 0;
    virtual void setGraphicsFps(int fps) = 0;
    virtual void setGraphicsBitrate(int32_t bps) = 0;

    virtual void setAspPlayer(AspPlayer *player) = 0;
    virtual void setAspAudio(AspAudio *audio) = 0;

    virtual void setOutputImageFormat(AspImageFormat format) = 0;
    virtual void setProxyConnType(AspConnType connType) = 0;
    virtual void setQuicOption(bool option) = 0;

    virtual bool sendStringDataToShell(const std::string& val) = 0;
    virtual bool sendRawDataToShell(const std::vector<uint8_t> val) = 0;
    virtual void setShellCmdCallback(wuying::asp::shared_ptr<IShellCmdCallback> shellCmdCallback) = 0;

    virtual void setClipBoardTypes(std::vector<AspClipboardType> types) = 0;
    virtual void notifyClipboardReadComplete(AspClipboardType type, uint8_t* buf, size_t len) = 0;
    virtual void setClipboardCallback(wuying::asp::shared_ptr<IClipboardCallback> clipboardCallback) = 0;
    virtual void requestGraphicsKeyFrame(AspDisplay* display) = 0;
    virtual void enableStatistics(bool enable, bool enableGuestInfo) = 0;
    virtual void sendDecodeFpsToAnalysis(uint64_t fps) = 0;
    virtual void setStatisticCallback(wuying::asp::shared_ptr<IStatisticCallback> statisticCallback) = 0;  

};

}
}


#endif //_ASP_CLIENT_H
