/*
 * Copyright 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/>.
 */

#ifndef BAIDUVISIONENGINE_P_H
#define BAIDUVISIONENGINE_P_H

#include <functional>
#include <string>
#include <kylin-ai/ai-engine/large-model/error.h>
#include <kylin-ai/ai-engine/large-model/cloudvisionengine.h>

class BaiduVisionEnginePrivate : public ai_engine::lm::vision::AbstractCloudVisionEngine {
public:
    BaiduVisionEnginePrivate();
    ~BaiduVisionEnginePrivate();
    std::string engineName();

    void setAppId(const std::string &appId);
    void setApiKey(const std::string &apiKey);
    void setSecretKey(const std::string &secretKey);

    void setPrompt2ImageCallback(ai_engine::lm::vision::ImageResultCallback callback);
    void setPrompt2ImageSize(int width, int height);
    void setPrompt2ImageNumber(int number);
    void setPrompt2ImageStyle(int style);

    ai_engine::ErrorCode prompt2Image(const std::string &prompt);

private:
    std::string appId_;
    std::string apiKey_;
    std::string secretKey_;
    std::string accessToken_;
    std::string &getAccessToken_();
    void generateAccessToken_();

    ai_engine::lm::vision::ImageResultCallback imageResultCallback_;

    int imageWidth_{1024};
    int imageHeight_{1024};
    int imageNumber_{1};
    std::string imageStyle_;

    std::string requestPrompt2ImageTask(const std::string &prompt);
    ai_engine::ErrorCode processPrompt2ImageTask(const std::string &taskId);
    std::string doRequestTaskResult(const std::string &taskId);

    int resultCode_{0};
    std::string lastErrorMessage_;
};

#endif // BAIDUVISIONENGINE_P_H
