#pragma once

/**
 * StoryChain文件定义.
 */
#include <QString>
#include <QList>
#include "ParseFrame.h"
#include "XSyntaxBase.h"
#include "comndef.h"


namespace Parse 
{
	class NodeStoryPoint;

	/**
	 * 故事脉络节点定义.
	 */
    class NodeStoryChain : public Result::NamedNode
	{
	public:
		/**
		 * 构建一个新的脉络节点.
		 * 
		 * \param src_path 源文件路径
		 */
        explicit NodeStoryChain(Result::DocCore *doc, const QString &name);
		virtual ~NodeStoryChain() = default;

		/**
		 * 获取此解析节点关联的源文件路径.
		 * 
		 * \return 路径字符串
		 */
		virtual QString srcPath() const;


		// 通过 NamedNode 继承
		inline virtual int depth() const override {
			return 0;
		}
		virtual QString name() const override;
        virtual Result::DocCore * document() const override;
		virtual int typeValue() const override;
		virtual DesNode * parent() const override;
		virtual void appendChild(DesNode * ins) override;
		virtual QList<DesNode*> children() const override;
		virtual bool check(QList<QString>& reasons) const override;
		virtual QString toString() const override;

	private:
        Result::DocCore *const doc_store;
		QString name_store;
		QList<DesNode*> children_nodes;
	};

	/**
	 * 故事脉络定制解析器.
	 */
	class NodeStoryChainParser : public Syntax::XSyntaxBase
	{
	public:
        NodeStoryChainParser(Result::ProjectCore *core);
		virtual ~NodeStoryChainParser() = default;

        Result::ProjectCore* project() const;

	private:
        Result::ProjectCore *pjt_ref;
	};

	/**
	 * 故事节点.
	 */
    class NodeStoryPoint : public Result::NamedNode
	{
	public:
		explicit NodeStoryPoint(NodeStoryChain *chain, const QString &name);
		virtual ~NodeStoryPoint() = default;

		/**
		 * 获取此解析节点依附的脉络节点
		 *
		 * \return 脉络节点
		 */
		virtual NodeStoryChain* storyChain() const;

		// 通过 NamedNode 继承
		inline virtual int depth() const override {
			return chain_store->depth() + 1;
		}
        virtual Result::DocCore * document() const override;
		virtual int typeValue() const override;
		virtual DesNode * parent() const override;
		virtual void appendChild(DesNode * ins) override;
		virtual QList<DesNode*> children() const override;
		virtual bool check(QList<QString>& reasons) const override;
		virtual QString toString() const override;
		virtual QString name() const override;

	private:
		NodeStoryChain *const chain_store;
		QString name_store;
		QList<DesNode*> children_nodes;
	};

	/**
	 * 故事节点定制解析器.
	 */
	class NodeStoryPointParser : public Syntax::XSyntaxBase
	{
	public:
		explicit NodeStoryPointParser(NodeStoryChainParser *chain);
		virtual ~NodeStoryPointParser() = default;

		NodeStoryChainParser* storyChainParser() const;
        virtual Result::DocCore* docRef() const override;

	private:
		NodeStoryChainParser *const parent_parser;
	};

	/**
	 * 节点描述内容节点.
	 */
    class NodeStoryDesGroup : public Result::DesNode
	{
	public:
		NodeStoryDesGroup(DesNode *parent_refer);
		virtual ~NodeStoryDesGroup() = default;

		// 通过 DesNode 继承
		inline virtual int depth() const override {
			return parent_refer->depth() + 1;
		}
        virtual Result::DocCore * document() const override;
		virtual int typeValue() const override;
		virtual DesNode * parent() const override;
		virtual void appendChild(DesNode * ins) override;
		virtual QList<DesNode*> children() const override;
		virtual bool check(QList<QString>& reasons) const override;
		virtual QString toString() const override;

	private:
		DesNode *const parent_refer;
		QList<DesNode*> children_nodes;
	};

	class NodeStoryPureTextDesGroupParser : public Syntax::XSyntaxBase
	{
	public:
		explicit NodeStoryPureTextDesGroupParser(XSyntaxBase *pparser);
		virtual ~NodeStoryPureTextDesGroupParser() = default;

	private:
		XSyntaxBase *const parent_parser;
	};

	/**
	 * 描述内容文字块.
	 */
    class NodeStoryDesBlock : public Result::DesNode
	{
	public:
        explicit NodeStoryDesBlock(DesNode *parent_node, const QString &text);
		virtual ~NodeStoryDesBlock() = default;

		// 通过 DesNode 继承
		inline virtual int depth() const override {
			return parent_refer->depth() + 1;
		}
        virtual Result::DocCore * document() const override;
		virtual int typeValue() const override;
		virtual DesNode * parent() const override;
		virtual void appendChild(DesNode * ins) override;
		virtual QList<DesNode*> children() const override;
		virtual bool check(QList<QString>& reasons) const override;
		virtual QString toString() const override;

	private:
		DesNode *const parent_refer;
		QString text_block;
	};

    class StoryChainDocumentParser : public Syntax::ParseFrame
	{
	public:
        StoryChainDocumentParser(Result::ProjectCore *pjt);
		virtual ~StoryChainDocumentParser() = default;
	};
}

