#pragma once

#include "ISTTService.hpp"
#include "../shared/audio/ISTTEngine.hpp"
#include <nlohmann/json.hpp>
#include <spdlog/spdlog.h>
#include <memory>
#include <string>

namespace celuna {

/**
 * @brief STT Service implementation
 *
 * Phase 7.1 - MVP: Simple service with single engine (Vosk)
 * TODO Phase 7.2: Add passive mode (PocketSphinx keyword spotting)
 */
class STTService : public ISTTService {
public:
    explicit STTService(const nlohmann::json& config);
    ~STTService() override;

    bool start() override;
    void stop() override;

    void setMode(STTMode mode) override;
    STTMode getMode() const override { return m_currentMode; }

    std::string transcribeFile(const std::string& filePath) override;
    std::string transcribe(const std::vector<float>& audioData) override;

    void startListening(TranscriptionCallback onTranscription,
                       KeywordCallback onKeyword) override;
    void stopListening() override;

    void setLanguage(const std::string& language) override;
    bool isAvailable() const override;
    std::string getCurrentEngine() const override;

private:
    // Configuration
    nlohmann::json m_config;
    std::string m_language = "fr";

    // Engines (MVP: only active engine)
    std::unique_ptr<ISTTEngine> m_activeEngine;

    // State
    STTMode m_currentMode = STTMode::ACTIVE;
    bool m_listening = false;

    // Callbacks
    TranscriptionCallback m_onTranscription;
    KeywordCallback m_onKeyword;

    // Logger
    std::shared_ptr<spdlog::logger> m_logger;

    // Helpers
    void loadEngines();
};

} // namespace celuna
