#include "ISTTEngine.hpp"
#include "WhisperAPIEngine.hpp"
#include <spdlog/spdlog.h>

namespace aissia {

// Stub STT for when API key is not available
class StubSTTEngine : public ISTTEngine {
public:
    std::string transcribe(const std::vector<float>& audioData) override {
        spdlog::info("[STT Stub] Would transcribe {} samples", audioData.size());
        return "";
    }
    std::string transcribeFile(const std::string& filePath) override {
        spdlog::info("[STT Stub] Would transcribe file: {}", filePath);
        return "";
    }
    void setLanguage(const std::string& language) override {}
    bool isAvailable() const override { return false; }
    std::string getEngineName() const override { return "stub"; }
};

std::unique_ptr<ISTTEngine> STTEngineFactory::create(const std::string& apiKey) {
    auto logger = spdlog::get("STTFactory");
    if (!logger) {
        logger = spdlog::stdout_color_mt("STTFactory");
    }

    if (!apiKey.empty()) {
        auto engine = std::make_unique<WhisperAPIEngine>(apiKey);
        if (engine->isAvailable()) {
            logger->info("Using Whisper API STT engine");
            return engine;
        }
    }

    logger->warn("No STT engine available (API key missing), using stub");
    return std::make_unique<StubSTTEngine>();
}

} // namespace aissia
