using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;

using CategoryTheory;
using DiagramUI;

namespace DataPerformer
{
    [Serializable()]
    public class ObjectTransformerLink : ISerializable, ICategoryArrow, IRemovableObject
    {
        IObjectTransformer target;
        IObjectTransformerConsumer source;
        object obj;


        public ObjectTransformerLink()
        {
        }

        public ObjectTransformerLink(SerializationInfo info, StreamingContext context)
        {
        }

        #region ISerializable Members

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
        }

        #endregion

        #region ICategoryArrow Members

        ICategoryObject ICategoryArrow.Source
        {
            get
            {
                return source as ICategoryObject;
            }
            set
            {
                if (!(value is IObjectTransformerConsumer))
                {
                    CategoryException.ThrowIllegalSourceException();
                }
                source = value as IObjectTransformerConsumer;
            }
        }

        ICategoryObject ICategoryArrow.Target
        {
            get
            {
                return target as ICategoryObject;
            }
            set
            {
                if (!(value is IObjectTransformer))
                {
                    CategoryException.ThrowIllegalTargetException();
                }
                target = value as IObjectTransformer;
                source.Add(target);
            }
        }

        bool ICategoryArrow.IsMonomorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        bool ICategoryArrow.IsEpimorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        bool ICategoryArrow.IsIsomorphism
        {
            get { throw new Exception("The method or operation is not implemented."); }
        }

        ICategoryArrow ICategoryArrow.Compose(ICategory category, ICategoryArrow next)
        {
            throw new Exception("The method or operation is not implemented.");
        }

        #endregion

        #region IAssociatedObject Members

        object IAssociatedObject.Object
        {
            get
            {
                return obj;
            }
            set
            {
                obj = value;
            }
        }

        #endregion

        #region IRemovableObject Members

        void IRemovableObject.RemoveObject()
        {
            source.Remove(target);
        }

        #endregion
    }
}
