#ifndef DEVICE_CTRL_GENERAL_SPKBOX_H
#define DEVICE_CTRL_GENERAL_SPKBOX_H
#include "spkbox.h"
#include <nlohmann/json.hpp>

#include "common/utils/json_util.h"

namespace zsy
{
    struct PlayResult
    {
        int32_t code;
        std::string message;
    };

    inline void from_json(const nlohmann::json &j, PlayResult &o)
    {
        JSON_FIELD(code);
        JSON_FIELD(message);
    }

    /*
    *{
                "loop": {"times", 2,"gap":2},
                "prompt": true,
                "queue": true,
                "rcn": "0",
                "rdn": "0",
                "reg": 0,
                "speed": 50,
                "sync": true,
                "text": content,
                "vcn": "xiaoyan",
                "volume": 100
            };
     */
    struct PlayLoop
    {
        int times = 2;
        int gap = 2;
    };

    struct PlayParam
    {
        PlayLoop loop;
        bool prompt = true;
        bool queue = true;
        std::string rcn = "0";
        std::string rdn = "0";
        int reg = 0;
        int speed = 50;
        bool sync = true;
        std::string text;
        std::string vcn = "xiaoyan";
        int volume = 100;
    };

    inline void to_json(nlohmann::json &j, const PlayLoop &loop)
    {
        j = nlohmann::json{
            {"times", loop.times},
            {"gap", loop.gap}
        };
    }

    inline void to_json(nlohmann::json &j, const PlayParam &config)
    {
        j = nlohmann::json{
            {"loop", config.loop},
            {"prompt", config.prompt},
            {"queue", config.queue},
            {"rcn", config.rcn},
            {"rdn", config.rdn},
            {"reg", config.reg},
            {"speed", config.speed},
            {"sync", config.sync},
            {"text", config.text},
            {"vcn", config.vcn},
            {"volume", config.volume}
        };
    }

    class GeneralSpkbox : public Spkbox
    {
        std::string playEndpoint;

    public:
        GeneralSpkbox(const SpkboxConfig &config);

        ~GeneralSpkbox() override = default ;

        void play(const std::string &content, uint8_t times = 1) override;
    };
} // zsy

#endif //DEVICE_CTRL_GENERAL_SPKBOX_H