﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Xml;

namespace LogTailer.Data.DataSettings
{
	public	class Root
	{
		/// <summary>
		/// FontFamily
		/// </summary>
		[DefaultValue("Source Han Code JP Light")]
		public	FontFamily	FontFamily
		{
			get;
			private	set;
		}
		/// <summary>
		/// 文字サイズ
		/// </summary>
		[DefaultValue("13")]
		public	double	FontSize
		{
			get;
			private	set;
		}

		public	List<Tailer>	Tailers
		{
			get;
			private	set;
		}

		/// <summary>
		/// コンストラクタ
		/// </summary>
		public	Root()
		{
			FontFamily	= new FontFamily( "Source Han Code JP Light" );
			FontSize	= 13;
			Tailers		= new List<Tailer>();
		}
	
		/// <summary>
		/// 読み込み
		/// </summary>
		/// <param name="tailerElement"></param>
		public	void	Load( XmlElement tailerElement )
		{
			// 属性
			foreach( XmlAttribute attribute in tailerElement.Attributes )
			{
				var	attributeName	= attribute.Name.ToLower();

				switch( attributeName )
				{
				case	"fontfamily":
					FontFamily	= new FontFamily( attribute.Value );
					break;
				case	"fontsize":
					FontSize	= double.Parse( attribute.Value );
					break;
				default:
					Debug.Assert( false, "未知の属性 attributeName={0}", attributeName );
					break;
				}
			}

			// 要素
			foreach( XmlNode childNode in tailerElement.ChildNodes )
			{
				var	elementName	= childNode.Name.ToLower();

				switch( elementName )
				{
				case	"tailer":
					var	tailer	= new Tailer();
					tailer.Load( childNode as XmlElement );
					Tailers.Add( tailer );
					break;
				default:
					Debug.Assert( false, "未知の要素 elementName={0}", elementName );
					break;
				}
			}
		}
	}
}
