#pragma once

#include <memory>
#include <thread>
#include <atomic>
#include <string>
#include <vector>
#include "../utils/ThreadSafeQueue.h"

namespace secondvoice {

class AudioCapture;
class WhisperClient;
class ClaudeClient;
class TranslationUI;
class AudioBuffer;

struct AudioChunk {
    std::vector<float> data;
    int sample_rate;
    int channels;
};

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

    bool initialize();
    bool start();
    void stop();

    // Call this from main thread for UI updates
    void update();

    bool isRunning() const { return running_; }
    bool shouldClose() const;

    // Clear accumulated translations
    void clearAccumulated();

private:
    void audioThread();
    void processingThread();

    std::unique_ptr<AudioCapture> audio_capture_;
    std::unique_ptr<WhisperClient> whisper_client_;
    std::unique_ptr<ClaudeClient> claude_client_;
    std::unique_ptr<TranslationUI> ui_;
    std::unique_ptr<AudioBuffer> full_recording_;

    ThreadSafeQueue<AudioChunk> audio_queue_;

    std::thread audio_thread_;
    std::thread processing_thread_;

    std::atomic<bool> running_{false};
    std::atomic<int> recording_duration_{0};

    // Simple accumulation
    std::string accumulated_chinese_;
    std::string accumulated_french_;
};

} // namespace secondvoice
