using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;

namespace Innovation
{
    // Information about Services
    struct ServiceData
    {
        public string Type;
        public bool IsService;
    }

    // Provides a link between the Component class and Serializer class. A component
    // adds data and keys to this class to simplify serialization
    public class SerializationData
    {
        // Dictionary that stores the data. It is public so the Serializer can save
        // the data it holds.
        public Dictionary<string, object> Data = new Dictionary<string, object>();

        // Add data to the dictionary with the string key Key and value object Data
        public void AddData(string Key, object Data)
        {
            this.Data.Add(Key, Data);
        }

        // Get data of type T from the dictionary with the string key Key
        public T GetData<T>(string Key)
        {
            object val = this.Data[Key];
            return (T)val;
        }

        // Whether or not the data contains the specified Key
        public bool ContainsData(string Key)
        {
            return Data.ContainsKey(Key);
        }

        public XmlWriter Writer
        {
            get { return Writer; }
        }

        // The serializer being used for serialization/deserialization
        Serializer serializer;
        XmlWriter writer;

        // Constructor sets the serializer being used
        public SerializationData(Serializer Serializer, XmlWriter Writer)
        {
            serializer = Serializer;
            writer = Writer;
        }

        // Tell the serializer we will be using the specified Type
        public void AddDependency(Type type)
        {
            serializer.Dependency(type);
        }

        // Get the Type specified through the serializer, so the right
        // Assembly will be used.
        public Type GetTypeFromDependency(string type)
        {
            return Assembly.Load(serializer.DependencyMap[type]).GetType(type);
        }
    }
}
