#pragma once

#include <cstdint>
#include <string>
#include <vector>

struct RTMP;

/**
 * Low-level librtmp wrapper for RTMP streaming.
 * Ported from FLCKRtmpClient (UE5 LCKStreaming plugin).
 * All methods should be called from the same thread (encoder thread).
 */
class RtmpClient {
public:
    RtmpClient();
    ~RtmpClient();

    bool Connect(const std::string& rtmpUrl);
    void Disconnect();
    bool IsConnected() const;

    bool SendAvcSequenceHeader(const uint8_t* extraData, uint32_t extraDataSize);
    bool SendAacSequenceHeader(uint32_t sampleRate, uint32_t numChannels);
    bool SendVideoPacket(const uint8_t* data, uint32_t size, uint32_t timestampMs, bool isKeyframe);
    bool SendAudioPacket(const uint8_t* data, uint32_t size, uint32_t timestampMs);

private:
    bool SendRtmpPacket(uint8_t packetType, uint32_t timestampMs, const uint8_t* data, uint32_t size);
    static void BuildAudioSpecificConfig(uint8_t outConfig[2], uint32_t sampleRate, uint32_t numChannels);

    RTMP* rtmpContext = nullptr;
    bool connected = false;
};
