#pragma once
#include "AiDemoTypes.h"

// Demo AI output port: AI JSON result -> SDK OSD text + detection rectangles.
// The rectangle overlay itself is implemented in SDK OSD, not as a demo workaround.
class AiOutputPort
{
public:
    AiOutputPort();
    void SetOsdPort(HWS_PORT osdPort);
    void SetTextItemId(int itemId);
    void SetVideoSize(int width, int height);
    void EnsureDefaultTextItem();
    void ApplyResult(const AiDemoResult& result);
    void SetStatusText(const wchar_t* text);
    void ClearDetections();
    void ClearEvents();
    void SetVideoOverlayEnabled(bool enable);
    void SetSubtitleText(const wchar_t* text);

private:
    void ApplyDetections(const AiDemoResult& result);
    void ApplyEvents(const AiDemoResult& result);
    void ApplyAudioSubtitle(const AiDemoResult& result);
    bool IsAudioResult(const AiDemoResult& result) const;

private:
    HWS_PORT osd_;
    int textItemId_;
    int eventTextItemId_;
    int subtitleItemId_;
    int detectionBaseItemId_;
    int lastDetectionItemCount_;
    unsigned long long lastEventTickMs_;
    bool videoOverlayEnabled_;
    int videoWidth_;
    int videoHeight_;
};
