using System.Collections.ObjectModel;
using System.Xml;
using Machinations.UserComponents;

namespace Machinations.FromFlash.graph
{
    /// <summary>
    /// inner graph of user components
    /// </summary>
    public class UserComponentGraph : Graph
    {
        private readonly IUserComponentSchema m_userComponent;

        public UserComponentGraph(IUserComponentSchema userComponent)
        {
            m_userComponent = userComponent;
        }

        public ObservableCollection<InnerInOut> Inputs
        {
            get { return new ObservableCollection<InnerInOut>(m_userComponent.InnerInOuts);}
        }

        public IUserComponentSchema Component
        {
            get { return m_userComponent; }
        }

        public override XmlDocument GenerateXml()
        {
            SortAndSetIds();
            XmlDocument document = new XmlDocument();
//            UserComponentsSave(document);
            m_elements.ForEach(element => document.AppendChild(element.GenerateXml(document)));
            
            var xml = base.GenerateXml();
            foreach (var inOut in m_userComponent.InnerInOuts)
            {
                xml.AppendChild(inOut.GenerateXml(xml));
            }
            return xml;
        }
    }
}