#pragma once

#include "ISTTEngine.hpp"
#include <spdlog/spdlog.h>
#include <memory>
#include <vector>
#include <string>

// whisper.cpp forward declarations (to avoid including full headers)
struct whisper_context;
struct whisper_full_params;

namespace celuna {

/**
 * @brief Whisper.cpp Speech-to-Text engine
 *
 * Local high-quality STT using OpenAI's Whisper model via whisper.cpp.
 * Runs entirely offline with excellent accuracy.
 *
 * Features:
 * - High accuracy (OpenAI Whisper quality)
 * - Completely offline (no internet required)
 * - Multiple model sizes (tiny, base, small, medium, large)
 * - Multilingual support
 *
 * Model sizes:
 * - tiny: ~75MB, fastest, less accurate
 * - base: ~142MB, balanced
 * - small: ~466MB, good quality
 * - medium: ~1.5GB, very good
 * - large: ~2.9GB, best quality
 *
 * Recommended: base or small for most use cases
 */
class WhisperCppEngine : public ISTTEngine {
public:
    /**
     * @brief Construct Whisper.cpp engine
     * @param modelPath Path to Whisper GGML model file (e.g., "models/ggml-base.bin")
     */
    explicit WhisperCppEngine(const std::string& modelPath);

    ~WhisperCppEngine() override;

    // Disable copy
    WhisperCppEngine(const WhisperCppEngine&) = delete;
    WhisperCppEngine& operator=(const WhisperCppEngine&) = delete;

    std::string transcribe(const std::vector<float>& audioData) override;
    std::string transcribeFile(const std::string& filePath) override;
    void setLanguage(const std::string& language) override;
    bool isAvailable() const override;
    std::string getEngineName() const override;

    /**
     * @brief Set transcription parameters
     * @param threads Number of threads to use (default: 4)
     * @param translate Translate to English (default: false)
     */
    void setParameters(int threads = 4, bool translate = false);

private:
    bool initialize();
    void cleanup();
    std::string processAudioData(const float* audioData, size_t numSamples);

    std::shared_ptr<spdlog::logger> m_logger;
    std::string m_modelPath;
    std::string m_language = "auto";
    bool m_available = false;
    int m_threads = 4;
    bool m_translate = false;

    // whisper.cpp context (opaque pointer to avoid header dependency)
    whisper_context* m_ctx = nullptr;
};

} // namespace celuna
