#ifndef SCAR_VIDEO_ENCODER_H
#define SCAR_VIDEO_ENCODER_H

#include <vector>
#include <cstdint>
#include <memory>

extern "C" {
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
}

namespace scar {

class VideoEncoder {
public:
    VideoEncoder();
    ~VideoEncoder();

    // Initialize encoder with given parameters
    bool initialize(int width, int height, int fps = 30, int bitrate = 2000000);
    
    // Encode a raw frame (BGR0 format from PipeWire)
    // Returns encoded packet data, empty if error or no packet yet
    std::vector<uint8_t> encode(const uint8_t* frame_data, uint32_t frame_size);
    
    // Flush any remaining frames
    std::vector<uint8_t> flush();
    
    // Cleanup
    void cleanup();

private:
    AVCodecContext* codec_ctx_;
    AVFrame* frame_;
    AVPacket* packet_;
    SwsContext* sws_ctx_;
    
    int width_;
    int height_;
    int frame_counter_;
    
    bool initialized_;
};

} // namespace scar

#endif // SCAR_VIDEO_ENCODER_H
