/*
 * Copyright (C) 2024 KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <https://www.gnu.org/licenses/>.
 */

#include "ondeviceembeddingengine.h"

#include "src/embeddingserver.h"

namespace ai_engine {
namespace core_ai {
namespace embedding {

OndeviceEmbeddingEngine::OndeviceEmbeddingEngine()
    : embeddingServer_(new EmbeddingServer) {}
OndeviceEmbeddingEngine::~OndeviceEmbeddingEngine() {
    if (!embeddingServer_) {
        delete embeddingServer_;
        embeddingServer_ = nullptr;
    }
}
void OndeviceEmbeddingEngine::setEmbeddingResultCallback(
    EmbeddingResultCallback callback) {
    if (!callback) {
        std::cerr << "EmbeddingResultCallback is nullptr" << std::endl;
        return;
    }
    embeddingServer_->setEmbeddingResultCallback(callback);
}

std::string OndeviceEmbeddingEngine::modelInfo() const {
    return embeddingServer_->modelInfo();
}

// 文本向量化
result::AiEngineBaseResult OndeviceEmbeddingEngine::initTextEmbeddingModule() {
    return embeddingServer_->initTextEmbeddingModule();
}
result::AiEngineBaseResult
OndeviceEmbeddingEngine::destroyTextEmbeddingModule() {
    return embeddingServer_->destroyTextEmbeddingModule();
}
result::AiEngineBaseResult OndeviceEmbeddingEngine::embeddingText(
    const std::string &text) {
    return embeddingServer_->embeddingText(text);
}

// 图像向量化
result::AiEngineBaseResult OndeviceEmbeddingEngine::initImageEmbeddingModule() {
    return embeddingServer_->initImageEmbeddingModule();
}
result::AiEngineBaseResult
OndeviceEmbeddingEngine::destroyImageEmbeddingModule() {
    return embeddingServer_->destroyImageEmbeddingModule();
}
result::AiEngineBaseResult OndeviceEmbeddingEngine::embeddingImageFromImageFile(
    const std::string &filePath) {
    return embeddingServer_->embeddingImageFromImageFile(filePath);
}
result::AiEngineBaseResult
OndeviceEmbeddingEngine::embeddingImageFromBase64ImageData(
    const std::string &fileData) {
    return embeddingServer_->embeddingImageFromBase64ImageData(fileData);
}
result::AiEngineBaseResult OndeviceEmbeddingEngine::embeddingTextWithImageModel(
    const std::string &text) {
    return embeddingServer_->embeddingTextWithImageModel(text);
}

}  // namespace embedding
}  // namespace core_ai
}  // namespace ai_engine