using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
using System.Collections.Generic;

[System.Serializable]
public class DialogNode
{
	[XmlAttribute ("id")]
	public string id = ""; // id of node for search and selection
	[XmlAttribute ("quest")]
	public string question = ""; // main node text/text tag(for translate)
	[XmlArray ("actions")]
	public TriggerAction[] actions = null; // actions on activate
	[XmlArray ("answers")]
	public DialogAnswer[] answers = null; // optional

	public string GetNextNode(int i)
	{
		if (i < answers.Length && i >= 0)
		{
			answers[i].InvokeActions();
			return answers[i].nextNodeId;
		}
		return "";
	}

	public void InvokeActions()
	{
		if (actions != null)
		{
			foreach(var action in actions)
			{
				if (action != null)
				{
					action.Invoke();
				}
			}
		}
	}

	public string[] GetAnswersList()
	{
		List<string> answersList = new List<string> ();
		foreach (var answer in answers)
		{
			if (answer.CheckConditions())
			{
				answersList.Add(answer.answer);
			}
		}
		return answersList.ToArray ();
	}
}