#ifndef ADAPTER_H
#define ADAPTER_H

#include "spdlog/spdlog.h"
#include <string>


/* 强盗类 */
class Foreigner
{
public:
    /* 忏悔 */
    virtual std::string confession() = 0;
    void setResult(std::string result)
    {
        SPDLOG_INFO("熊猫说:{}", result);
    }
    virtual ~Foreigner() {}
};

/* 美国人 */
class American : public Foreigner
{
public:
    std::string confession() override
    {
        return "我是美国人，我是强盗";
    }

};

/* 法国人 */
class French : public Foreigner
{
public:
std::string confession() override
    {
        return "我是法国人，我是强盗";
    }
};

/* 熊猫类 */
class Panda
{
public:
    void receiveMsg(std::string& msg)
    {
        SPDLOG_INFO("熊猫收到消息:{}", msg);
    }
    std::string sendMsg()
    {
        return "强盗、凶手、罪人是不可能被宽恕和原谅的！";
    }
};


/* 抽象翻译类 */
class AbstractTranslator
{
public:
    AbstractTranslator(Foreigner* foreigner) : m_foreign(foreigner) {}
    virtual ~AbstractTranslator() {}
    virtual void translateToForeigner() = 0;
    virtual void translateToPanda() = 0;

protected:
    Foreigner* m_foreign = nullptr;
    Panda m_panda;
};

/* 英语适配器翻译机 */
class EnglishAdapter : public AbstractTranslator
{
public:
    /* 继承父类的所有构造函数 */
    using AbstractTranslator::AbstractTranslator;
    void translateToForeigner() override
    {
        std::string msg = m_panda.sendMsg();
        m_foreign->setResult(msg);
    }
    void translateToPanda() override
    {
        std::string msg = m_foreign->confession();
        m_panda.receiveMsg(msg);
    }

};

/* 法语适配器翻译机 */
class FrenchAdapter : public AbstractTranslator
{
public:
    /* 继承父类的所有构造函数 */
    using AbstractTranslator::AbstractTranslator;
    void translateToForeigner() override
    {
        std::string msg = m_panda.sendMsg();
        m_foreign->setResult(msg);
    }
    void translateToPanda() override
    {
        std::string msg = m_foreign->confession();
        m_panda.receiveMsg(msg);
    }

};

#endif /* APADTER_H */
