
class Statement;

/** Interface for HILTI statements. */
class Concept : public hilti::util::type_erasure::ConceptBase {
public:
    Concept() = default;
    Concept(const Concept&) = default;
    Concept(Concept&&) = default;
    virtual ~Concept() = default;
    /** Returns true if the statement is equivalent to another one in HILTI semantics. */
    virtual bool isEqual(const Statement& other) const = 0;
    /** Implements the `Node` interface. */
    virtual hilti::node::Properties properties() const = 0;
    /** Implements the `Node` interface. */
    virtual const std::vector<hilti::Node>& children() const = 0;
    /** Implements the `Node` interface. */
    virtual std::vector<hilti::Node>& children()  = 0;
    /** Implements the `Node` interface. */
    virtual const Meta& meta() const = 0;
    /** Implements the `Node` interface. */
    virtual void setMeta(Meta m)  = 0;
    /** Implements the `Node` interface. */
    virtual bool pruneWalk() const = 0;
    Concept& operator=(const Concept&) = default;
    Concept& operator=(Concept&&) = default;
    virtual Statement _clone() const = 0;
    virtual hilti::IntrusivePtr<Concept> _clone_ptr() const = 0;
private:
    
};

template<typename T>
using ModelBase = hilti::util::type_erasure::ModelBase<T, Concept>;

template<class T>
class Model : public ModelBase<T> {
public:
    using ModelBase<T>::ModelBase;
    using ModelBase<T>::data;

    bool isEqual(const Statement& other) const final;
    hilti::node::Properties properties() const final;
    const std::vector<hilti::Node>& children() const final;
    std::vector<hilti::Node>& children()  final;
    const Meta& meta() const final;
    void setMeta(Meta m)  final;
    bool pruneWalk() const final;
    Statement _clone() const final;
    hilti::IntrusivePtr<Concept> _clone_ptr() const final;
};

using ErasedBase = hilti::util::type_erasure::ErasedBase<trait::isStatement, Concept, Model>;

class Statement : public ErasedBase, public trait::isNode {
public:
    using ErasedBase::ErasedBase;

    Statement() noexcept = default;
    Statement(Statement&&) noexcept = default;
    Statement& operator=(Statement&&) = default;
    ~Statement() override = default;
    Statement(const Statement& other) = default;
    Statement& operator=(const Statement& other) = default;

    bool isEqual(const Statement& other) const;
    hilti::node::Properties properties() const;
    const std::vector<hilti::Node>& children() const;
    std::vector<hilti::Node>& children() ;
    const Meta& meta() const;
    void setMeta(Meta m) ;
    bool pruneWalk() const;
    Statement _clone() const;

    hilti::IntrusivePtr<Concept> _clone_ptr() const;

protected:
    
};

template<typename T>
bool Model<T>::isEqual(const Statement& other) const { return data().isEqual(other); }

template<typename T>
hilti::node::Properties Model<T>::properties() const { return data().properties(); }

template<typename T>
const std::vector<hilti::Node>& Model<T>::children() const { return data().children(); }

template<typename T>
std::vector<hilti::Node>& Model<T>::children()  { return data().children(); }

template<typename T>
const Meta& Model<T>::meta() const { return data().meta(); }

template<typename T>
void Model<T>::setMeta(Meta m)  { return data().setMeta(m); }

template<typename T>
bool Model<T>::pruneWalk() const { return data().pruneWalk(); }

template<typename T>
Statement Model<T>::_clone() const { return T(data()); }

template<typename T>
hilti::IntrusivePtr<Concept> Model<T>::_clone_ptr() const {
    if constexpr ( std::is_base_of<hilti::util::type_erasure::trait::Singleton, T>::value )
        return nullptr;
    else
        return hilti::make_intrusive<Model>(T(data()));
}

inline bool Statement::isEqual(const Statement& other) const { return data()->isEqual(other); }

inline hilti::node::Properties Statement::properties() const { return data()->properties(); }

inline const std::vector<hilti::Node>& Statement::children() const { return data()->children(); }

inline std::vector<hilti::Node>& Statement::children()  { return data()->children(); }

inline const Meta& Statement::meta() const { return data()->meta(); }

inline void Statement::setMeta(Meta m)  { return data()->setMeta(std::move(m)); }

inline bool Statement::pruneWalk() const { return data()->pruneWalk(); }

inline Statement Statement::_clone() const { return data() ? data()->_clone() : Statement(); }

inline hilti::IntrusivePtr<Concept> Statement::_clone_ptr() const {
    if ( data() )
        return data()->_clone_ptr();
    else
        return nullptr;
}



