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

[System.Serializable]
public class DialogAnswer {
	
	[XmlAttribute ("answer")]
	public string answer = ""; // answer text/text tag(for translate)
	[XmlAttribute ("next")]
	public string nextNodeId = ""; // next node selected after that answer
	[XmlArray ("conditions")]
	public Condition[] conditions = null; // optional - conditions of showing
	[XmlArray ("actions")]
	public TriggerAction[] actions = null; // optional - actions after answer selection
	
	public DialogAnswer() {}
	
	public DialogAnswer(string answerText, string nextNode, TriggerAction[] answerActions = null, Condition[] answerConditions = null) {
		answer = answerText;
		actions = answerActions;
		nextNodeId = nextNode;
		conditions = answerConditions;
	}
	public DialogAnswer(string answerText, TriggerAction[] answerActions = null, Condition[] answerConditions = null)
	{
		answer = answerText;
		actions = answerActions;
		conditions = answerConditions;
	}

	public void InvokeActions()
	{
		if (actions != null)
		{
			foreach(var action in actions)
			{
				if (action != null)
				{
					action.Invoke();
				}
			}
		}
	}
	
	public bool CheckConditions () {
		if (conditions != null) {
			foreach(var condition in conditions)
			{
				if (condition != null && !condition.Check())
				{
					return false;
				}
			}
		}
		return true;
	}
}